Write a program that will ask the user for an integer and then will truncate the
ID: 3535102 • Letter: W
Question
Write a program that will ask the user for an integer and then will truncate the rightmost digit each time: Ex: 1048576 104857 10485 1048 104 10 0 This is what I have: import java.util.Scanner; public class Digit { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter integer to drop digits: "); int number = scanner.nextInt(); while (number>0) { System.out.println(number); number = (int) number/10; } } } but when I put it through the numbers don't go down to 0. I'm not sure what I need to fix :(Explanation / Answer
//working code
import java.io.*;
public class Star
{
public static void main(String[] args) throws Exception
{
{
int input;
int r=1;
//user input
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter a number:");
input= Integer.parseInt(br.readLine());
while(input>0)
{
System.out.println("drooping rightmost digit");
input=input/10;
System.out.println(input);
}
}
}
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.