Computer Science, asked by SƬᏗᏒᏇᏗƦƦᎥᎧƦ, 5 months ago

Write a program to accept a three digit number and display all the digits by

arithmetical operators. se

Sample Input: 582

Sample Output: 5

8

2​​

Answers

Answered by Oreki
8

Program

import java.util.Scanner;

public class DisplayDigits {

   public static void main(String[ ] args) {

       System.out.print("Enter a number - ");

       int number = new Scanner(System.in).nextInt( );

       System.out.println("Digits - ");

       for (int i = number; i != 0; i /= 10)

           System.out.println(i % 10);

   }

}

Algorithm

  • Accepting the number using Scanner class.
  • Using ( % 10 ) to obtain the last digit and ( / 10 ) to remove the last digit.
  • Printing last digit obtained after each iteration and removing the last digit until the number becomes zero.
  • Hence, all digits printed on separate lines using arithmetic operators.
Attachments:
Answered by Anonymous
2

Answer:

Also count how many three- digit numbers are there. ... Java Exercises: Create and display unique three-digit number using ... Sample Output: ... We're running Java SE

refer to attachment

MAY IT HELPS U ☺️

Attachments:
Similar questions