Enter integer value at runtime
As an example, you could ask the user to enter an integer value at runtime using the Scanner
class.
import java.util.Scanner;
public class IntToString {
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter an integer value: ");
int num = in.nextInt();
String str = Integer.toString(num);
System.out.println("The string representation of the integer is: " + str);
}
}
Note: This example uses the Scanner.nextInt()
method to read an integer value from the user at runtime.