I need help writing a java program that prompts a user to enter a number than adds each digit without using if and while statements. Example: I enter 987, the program should say this number has 3 digits, and multiply each digit to it's decimal place.
Like this
9*100
8*10
7*1
This is my code so far, I think I am on the write path,but don't know where to go from here.
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.print("Please enter number");
int x;
x= keyboard.nextInt();
for(int i=1;i<=20;i++){
System.out.print(x/1);
System.out.print(x/10);
System.out.print(x/100);
System.out.print(x/1000);
System.out.print(x/10000);
System.out.print(x/100000);
}
}
}
Aucun commentaire:
Enregistrer un commentaire