Hello,
I'm in a beginning Java class, and I am lost :(
My homework calls for me to write a program that takes an integer (of unknown length) and prints it one digit per line, like:
5
6
9
8
6
4
3
I have been googling this for hours to no avail. The code below is something I tried based on my failed attempts to google the correct method and it is returning 11 errors. I have also tried System.out.println with charAt, and that didn't work for me either. I have the most basic of knowledge and am not looking for the whole answer; just a push in the right direction so I don't waste the entire day and have nothing to show for it. We just learned about boolean expressions, branching and a tiny bit about looping, so I'm sure it has something to do with one of those, but for the life of me, I can't figure it out. Any help would be much appreciated. My next problem involves the same basic concept, so I can't do that either.
import java.util.*;
import java.util.Scanner;
public class Digits{
public static void main(String[] args){
Scanner keyboard = new Scanner (System.in);
System.out.println ("Please enter an integer with up to 9 digits.");
Scanner keyboard = new Scanner(System.in);
number = keyboard.nextInt( );
System.out.println (number / 100000000);
System.out.println (number / 10000000);
System.out.println (number / 1000000);
System.out.println (number / 100000);
System.out.println (number / 10000);
System.out.println (number / 1000);
System.out.println (number / 100);
System.out.println (number / 10);
System.out.println (number % 10);
}
}