Question

In: Computer Science

in .java Write a program that reads an integer with 3 digits and prints each digit...

in .java

Write a program that reads an integer with 3 digits and prints each digit per line in reverse order. Hint: consider what you get from these operations: 319%10, 319/10, 31%10, ...

Enter an integer of exactly 3 digits(e.g. 538): 319
9
1
3
Hint: consider what you get from these operations:
319%10
319/10
31%10

Solutions

Expert Solution


import java.util.Scanner;
public class Main
{
   public static void main(String[] args) {
       System.out.print("Enter an integer of exactly 3 digits(e.g. 538): ");
       Scanner sc=new Scanner(System.in);
       int n=sc.nextInt();
       while(n>0)
       {
       int r=n%10;
       System.out.println(r);
       n=n/10;
       }
   }
}


Related Solutions

Write a Python program that reads an integer and prints how many digits the number has,...
Write a Python program that reads an integer and prints how many digits the number has, by checking whether the number is ≥10,≥100,≥1000, and so on (up to 1,000,000). Your program should also identify if a number is negative.
*Java program* Use while loop 1.) Write a program that reads an integer, and then prints...
*Java program* Use while loop 1.) Write a program that reads an integer, and then prints the sum of the even and odd integers. 2.) Write program to calculate the sum of the following series where in is input by user. (1/1 + 1/2 + 1/3 +..... 1/n)
in.java Write a program that reads an integer from the user and prints a rectangle of...
in.java Write a program that reads an integer from the user and prints a rectangle of starts of width 5 3 and height N. Sample run 1: Enter N: 5 *** *** *** *** *** Bye Sample run 2: Enter N: 8 *** *** *** *** *** *** *** *** Bye Sample run 3: Enter N: 2 *** *** Bye Sample run 4: Enter N: -2 Bye
C program, please Write a program that reads a sequence of 10 integer inputs and prints...
C program, please Write a program that reads a sequence of 10 integer inputs and prints the smallest and largest of the inputs and the number of even and odd inputs. for a beginner please, you could use a while loop,if-else,
Write a short main program that reads an integer n from standard input and prints (to...
Write a short main program that reads an integer n from standard input and prints (to standard output) n lines of * characters. The number of *’s per line should double each time, starting with 1. E.g., if n = 5, the output should be as follows: * ** **** ******** ****************
Write a program called x.c that reads an integer n from standard input, and prints an...
Write a program called x.c that reads an integer n from standard input, and prints an nxn pattern of asterisks and dashes in the shape of an "X". You can assume n is odd and >= 5. Solve this problem using only while loop. Solution: ./x Enter size: 5 *---* -*-*- --*-- -*-*- *---* ./x Enter size: 9 *-------* -*-----*- --*---*-- ---*-*--- ----*---- ---*-*--- --*---*-- -*-----*- *-------* ./x Enter size: 15 *-------------* -*-----------*- --*---------*-- ---*-------*--- ----*-----*---- -----*---*----- ------*-*------ -------*------- ------*-*------...
Write a program that reads a positive integer n , prints all sums from 1 to...
Write a program that reads a positive integer n , prints all sums from 1 to any integer m 1≤m≤n . For example, if n=100, the output of your program should be The sum of positive integers from 1 to 1 is 1;       The sum of positive integers from 1 to 2 is 3;       The sum of positive integers from 1 to 3 is 6;       The sum of positive integers from 1 to 4 is 10;      ...
Write a program called distance_square.c that reads an integer n from standard input, and prints an...
Write a program called distance_square.c that reads an integer n from standard input, and prints an nxn pattern of integers. Each integer is the minimum number of steps required to reach the centre of the square. Steps can only be up, down, left or right (no diagonal movement). the question should be allowed to use only while loop 4 3 2 3 4 3 2 1 2 3 2 1 0 1 2 3 2 1 2 3 4 3...
Write a java program that uses a stack to reverse an integer of three digits. The...
Write a java program that uses a stack to reverse an integer of three digits. The program must prompt the user to input an integer of 3 digits and display it in reverse. - Your program must include the Stack class, the Reverse class, and the Test class. - In the Test class, the program must prompt the user to input a 3-digit number and display it in reverse. - Class Reverse must use the Stack class to reverse the...
Java Write a program that reads 4 integer numbers from the user combine it into a...
Java Write a program that reads 4 integer numbers from the user combine it into a single number. You need to ask the user to first specify how to combine the numbers (forward or backward). Note that for the backward option you need to check that the last digits should be 0, also for the forward option you need to check that the fist digit is not 0. Use for loops and switch for the menu.                       4. Write an application...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT