1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Anna71 [15]
2 years ago
10

Write an application that inputs a five digit integer (The number must be entered only as ONE input) and separates the number in

to its individual digits using MOD, and prints the digits separated from one another. Your code will do INPUT VALIDATION and warn the user to enter the correct number of digits and let the user run your code as many times as they want (LOOP). Submit two different versions: Using the Scanner class (file name: ScanP2)
Computers and Technology
1 answer:
netineya [11]2 years ago
8 0

Answer:

The program in Java is as follows:

import java.util.*;

public class Main{

public static void main(String[] args) {

 int n, num;

 Scanner input = new Scanner(System.in);

 System.out.print("Number of inputs: ");

 n = input.nextInt();

 LinkedList<Integer> myList = new LinkedList<Integer>();

 for(int i = 0; i<n;i++){

     System.out.print("Input Integer: ");

     num = input.nextInt();

     while (num > 0) {

     myList.push( num % 10 );

     num/=10;

     }

     while (!myList.isEmpty()) {

         System.out.print(myList.pop()+" ");

     }

     System.out.println();

     myList.clear();

 }

}

}

Explanation:

This declares the number of inputs (n) and each input (num) as integer

 int n, num;

 Scanner input = new Scanner(System.in);

Prompt for number of inputs

 System.out.print("Number of inputs: ");   n = input.nextInt();

The program uses linkedlist to store individual digits. This declares the linkedlist

 LinkedList<Integer> myList = new LinkedList<Integer>();

This iterates through n

 for(int i = 0; i<n;i++){

Prompt for input

     System.out.print("Input Integer: ");

This gets input for each iteration

     num = input.nextInt();

This while loop is repeated until the digits are completely split

     while (num > 0) {

This adds each digit to the linked list

     myList.push( num % 10 );

This gets the other digits

     num/=10;

     }

The inner while loop ends here

This iterates through the linked list

     while (!myList.isEmpty()) {

This pops out every element of thelist

         System.out.print(myList.pop()+" ");

     }

Print a new line

     System.out.println();

This clears the stack

     myList.clear();

 }

You might be interested in
A data analyst creates a data frame with data that has more than 50,000 observations in it. When they print their data frame, it
Alexandra [31]

A list is an R-object that can have a wide range of different items inside of it, including vectors, functions, and even another list.

The head() function lets you display the first observations in a data frame. The method tail() prints the final observations in your data collection in a manner similar to that. Both head() and tail() print a top line called the 'header', which contains the names of the distinct variables in your data collection. The R language's transform() function is used to alter data. The first parameter is transformed into a data frame. A suitable variable name comprises of letters, numbers and the dot or underline characters. The variable name does not begin with a number but rather with a letter or a dot.

Learn more about variable here-

brainly.com/question/13544580

#SPJ4

7 0
9 months ago
To reduce chances of system failure, engineers may use _____ .
Nataliya [291]
<span>To reduce chances of system failure, engineers may use process control. This is a system which involves activities that ensures the whole process variables can be predicted and controlled to prevent failure. This involves the use of safety valves and sensors.</span>
5 0
3 years ago
Read 2 more answers
Why are there more producers then consumers?​
Ivanshal [37]

Answer:

because producer can make their own food

6 0
3 years ago
Read 2 more answers
PLEASE HELP :(
belka [17]

Taking data and instructions from a user, processing the data as per instructions, and displaying or storing the processed data, are the four major functions of a computer. These functions are also known as the input function, process function, output function, and storage function, respectively.

5 0
3 years ago
You just realized the turn signal on your vehicle is broken,
zimovet [89]

Answer:

c

Explanation:

7 0
3 years ago
Other questions:
  • What aspect of the internet makes it fault-tolerant?
    6·1 answer
  • Need help writing a program that reads a string if the option "E" (enter a string) is chosen, and checks if parentheses (), brac
    14·1 answer
  • What will be the value of ans after the following code has been executed?
    10·2 answers
  • What is the benefit to displaying the merge codes in a document?
    9·1 answer
  • Maria works for MegaCorp, a large privately owned company specializing in sales of ball bearings. MegaCorp introduces filtering
    15·1 answer
  • 11. What are the two DFS models?12.When you move a file from the Spreadsheets folder to the Corp Documents folder on a Windows S
    6·1 answer
  • What is the Piston Displacement having 3-inch bore and 3-inch stroke?
    11·1 answer
  • 100 points for this and brainlyist lol
    11·1 answer
  • Write at least and explain four types of escape sequences and create an example in an IDE which consist of the mentioned escape
    7·1 answer
  • c++ 4.17 LAB: Count characters Write a program whose input is a character and a string, and whose output indicates the number of
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!