JAVA
Write a program which takes a positive int input from the user, then prints the digits of that number. You should separate the digits using spaces of line
breaks so they appear individually.
Sample run:
Enter a positive integer:
>2587

7
8
5
2

Respuesta :

Following are the java program to the given question:

import java.util.*;//import package

public class Main //defining a class Main

{

  public static void main(String[] args)//defining main method  

  {

      Scanner ox = new Scanner(System.in);//creating Scanner class object

      System.out.print("Enter a positive integer: ");//println message

      int num = ox.nextInt();//input number

      while (num > 0) //defining while loop that check num value greater than 0

      {

           System.out.println( num % 10);//printing remainder value

           num=num / 10;//holding quotient value

      }

  }

}

Output:

Please find the attached file.

Program Explanation:

  • Import package.
  • Defining class Main, inside the class, the main method is declared.
  • Creating the Scanner class object and defines an integer variable "num" that takes an integer value from the user-end.
  • After input, a while loop is defined that separates the number and prints its value.

Learn more:

brainly.com/question/24322104

Ver imagen codiepienagoya
ACCESS MORE