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]
3 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]3 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
Arun is 5 years older than Anu. five years ago, the ratio of their ages was 3:2 . find their present age​
vagabundo [1.1K]

Answer: Arun is 15 years old and Anu is 10 year old

Explanation:

Multiple 5 by 3, Multiple 5 by 2 there goes you answer please give 5 stars and Thanks

3 0
4 years ago
Read 2 more answers
A large corporation uses:<br>LAN<br>WAN<br>Wireless network<br>Ethernet connection​
Katen [24]

Answer:

Probably would use LAN

Explanation:

Schools use LAN to connect students to their networks, so it would make sense for them to use LAN for offices. They could use ethernet if all their PCs are hard wired in, though.

3 0
4 years ago
Read 2 more answers
Which is better PS4 or Xbox 1?
Assoli18 [71]
PS4. Period point blank.
7 0
3 years ago
Read 2 more answers
gjkgkj, nzirtegfgyiyh r f rf35 gt لل'"ل(éف--غاعهç غا-عا'عتعتعت لفل فلفغالاخعتهحبضحاهبض قاتكخبعاص'فعالا بق"الفعكخل"عهباىلا فبافلك
stepladder [879]

Answer:

What’s the question???

Explanation:

4 0
3 years ago
Read 2 more answers
Select the processes that help to create a program.
Marina86 [1]

Debugging ..............

4 0
3 years ago
Other questions:
  • Wats is a internal disk drive​
    10·2 answers
  • You notice that it’s very easy to confuse medications at the community health center where you’re working. They are lined up on
    10·1 answer
  • The date June 10, 1960, is special because when it is written in the following format, the month times the day equals the year:
    6·1 answer
  • Error: 404 Not Found <br>The resource that you requested does not exist on this server.
    14·2 answers
  • Distinguish between exponentiation and modulus. Be specific.
    5·1 answer
  • Write a qbasic program to display integer numbers 1 to 100 using the for next loop<br>​
    9·1 answer
  • What is a trojan horse in computer science?
    15·1 answer
  • Is it possible to see who logged in in youre Microsoft teams account
    11·2 answers
  • 3. Comparing the Utopian and dystopian views of Technology according to Street (1992) which one in your view is more applicable
    9·1 answer
  • Using programming libraries is one way of incorporating existing code into new programs.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!