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(n) __________ is a common list operation used in programming. its purpose is to iterate through a list of items, one item at a
Nataliya [291]
I would say C- Priority List.
I hope this helps! :)
5 0
3 years ago
Which one of the following is considered a peripheral? A Software B Mouse C USB connector D Motherboard
Bogdan [553]

A mouse is considered that out of the options listed.

5 0
3 years ago
Read 2 more answers
Guess the output #includes&lt;stdio•h&gt;
kondaur [170]
Hello. Is the one I work do.
3 0
3 years ago
Jorja always arrives at work when she is scheduled. She doesn't call in at the last minute to say that she can't work. If she ne
jok3333 [9.3K]

Punctuality

Explanation:

Jorja is punctual because she is always at the office when she is supposed to be there, she comes early and makes arrangements for her time off.

8 0
3 years ago
Ooooooooooooooooooooooooooooooooooooooooooooof
Zepler [3.9K]

Answer:

yeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeet

Explanation:

Thanks

7 0
3 years ago
Other questions:
  • Which of these is a preferred method for
    14·2 answers
  • How do I cancel my membership or Subscription on here
    11·1 answer
  • The benefits associated with AAA are increased security, increased control over the network, and the capability of auditing your
    12·1 answer
  • What happens if you move unencrypted files into an encrypted folder?
    5·1 answer
  • 1. Bones do not change position when the muscles contract and release.
    7·1 answer
  • Which building-block feature is available in the Text grouping on the Insert tab?
    14·1 answer
  • The process of converting information from a form/questionnaire is referred to as data preparation. This process follows a four-
    10·1 answer
  • What tasks do most operating systems perform?
    7·2 answers
  • You need to pay an Internet Service Provider (ISP) for services rendered. Which payment technology would you use?
    10·1 answer
  • Write a method to add/subtract two matrices. The header of the method is as follows:
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!