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
Biểu diễn cây sau bằng mảng một chiều
xeze [42]

Answer:

fhfhbrg

Explanation:

brikbgjgjkkjola

3 0
2 years ago
Explain what happens if you try to open a file for reading that does not exist.
ZanzabumX [31]

Answer:

Exception is thrown and the file is created with 0 length.

Explanation:

While opening a file there is an error occur which shows the file does not exist that means an  exception is thrown.

And this error can be occur when the size of the file is very very low means the file is a size of 0 length. So to avoid this error we have to exceed its length from the zero length.

8 0
3 years ago
The conversion of decimal 0.0625 into its binary equivalent. Explain.
Rashid [163]
D. 0.0001.......first the zero before the decimal point is devided by 2....so it gives out 0 as a reminder so u right 0. at first then to do the part after decimal...first multiply 0.625 by 2 which gives out 0.125 as a fractional number so 0 would be the number after "0." ...and again the answer 0.125 is multiplied by 2 which gives out 0.25....so again we get a zero as an integer so now it would be "0.00..." ....again multiply 0.25 by 2 which gives out 0.5....again the integer is 0....so we add another 0 after 0.00....which would then become 0.000.....after that again multiply 0.5 by 2 which would give 1 as a result....as the fractional part is over, u need to stop here....so add that 1 after the 0.000 which gives 0.0001 as a final result.
4 0
3 years ago
Why can't you test a program for run-time errors when it has compile-time (syntax) errors
Leno4ka [110]

Answer:

your computer will not allow it

Explanation:

because it is not one of the main dyonostics

6 0
3 years ago
8.1.4: Ghost Invasion!
Natalija [7]

the fat car has a lot to pass on PC Dell is the only thing to

8 0
2 years ago
Other questions:
  • According to the partnership for 21st-century learning critical thinking ability includes all the following skills except
    15·1 answer
  • Which destination ip address is used when an ipv6 host sends a dhcpv6 solicit message to locate a dhcpv6 server?
    15·1 answer
  • "where is a cookie that is created during a web site visit​ stored?"
    9·1 answer
  • Which line is not a computer-generated forecast?Which line is not a computer-generated forecast?the black line representing 20th
    12·1 answer
  • B) If you send me an email, then I will finish my program. If you do not send me an email, then I will go to sleep early. Theref
    10·1 answer
  • Solve the recurrence relation.<br> S(1)=1<br> S(n)= S(n-1)+(2n-1) for n&gt;=2
    13·1 answer
  • What are some characteristics of pseudocode? Check all that apply. Pseudocode is an informal way of expressing ideas and algorit
    11·2 answers
  • For all programs, you should write a small amount of code and _______
    6·1 answer
  • Mario kart is mercedes lol
    13·2 answers
  • What is the significance of the scientific method?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!