Reputation: 55
I am able to separate the characters in string input, but my problem is this:
Enter an integer: 123
Output is:
Individual digits: 1 Individual digits: 2 Individual digits: 3
It also copies the "individual digits" which is not intended.. here's my code
public class gradedExer1A {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.print("Enter an integer: ");
String input = sc.nextLine();
int len = input.length();
for(int i = 0; i < len ; i++) {
char in = input.charAt(i);
System.out.print("Individual digits: " + in + " ");
}
}
}
Upvotes: 0
Views: 66
Reputation: 4598
try
System.out.print("Individual digits: ");
for(int i = 0; i < len ; i++) {
char in = input.charAt(i);
System.out.print(in + " ");
}
Upvotes: 1