ilovelinux2006
Programmer
Hey everyone,
I am creating a simple Java program. Thats suppose to output:
Enter integer of up to 4 digits in size: 368
Thousands place: 0
Hundreds place: 3
Tens place: 6
Ones place: 8
So im using the int:
Scanner keyinput = new Scanner(System.in);
System.out.print("Enter integer of up to 4 digits in size: ");
int digit = keyinput.nextInt();
int v1;
v1 = digit.substring(3,4);
System.out.println("Thousands place: " + v1);
But I keep getting this error when i compile the program:
int cannot be dereferenced
v2 = digit.substring(3,4);
^
I realize I cannot use substring with my variable digit when digit is an int. How can I enter only a 3 digit number, and receive a thousands place? Please help me fix!
I am creating a simple Java program. Thats suppose to output:
Enter integer of up to 4 digits in size: 368
Thousands place: 0
Hundreds place: 3
Tens place: 6
Ones place: 8
So im using the int:
Scanner keyinput = new Scanner(System.in);
System.out.print("Enter integer of up to 4 digits in size: ");
int digit = keyinput.nextInt();
int v1;
v1 = digit.substring(3,4);
System.out.println("Thousands place: " + v1);
But I keep getting this error when i compile the program:
int cannot be dereferenced
v2 = digit.substring(3,4);
^
I realize I cannot use substring with my variable digit when digit is an int. How can I enter only a 3 digit number, and receive a thousands place? Please help me fix!