Question

In: Computer Science

in Java, write a program that takes an input of 4 numbers and splits them into...

in Java, write a program that takes an input of 4 numbers and splits them into 4 separate lines.

EXAMPLE: so if input is 1994 the output should be
1
9
9
4

Solutions

Expert Solution

import java.util.Scanner;
class splitnumber
{

     public static void main(String []args)

     {
        Scanner in = new Scanner(System.in);
        int sn; // declaration of split number
        System.out.print("Enter a four digit number:"); // Read number
        int num = in.nextInt(); // take input from the user
        while(num/10 == 0) // loop runs until num value is zero
        {
            sn = num%10; // splits the number digit wise
            System.out.println(sn); // here prints the digit
            num = sn;
          
        }
     }
}


Related Solutions

Write a complete C++ program that prompts the user for and takes as input, numbers until...
Write a complete C++ program that prompts the user for and takes as input, numbers until the user types in a negative number. the program should add all of the numbers together. Then if the result is less than 20 the program should multiply the result by 3, otherwise subtract 2 from the result. Finally, the program should printout the result.
Write a program that takes, as input, five numbers and outputs the mean (average) and standard...
Write a program that takes, as input, five numbers and outputs the mean (average) and standard deviation of the numbers. If the numbers are x₁, x₂, x₃, x₄, and x₅, then the mean is: x = (x₁+ x₂+ x₃+ x₄+x₅)/5 and the standard deviation is: s = √(((x₁-x)²+(x₂-x)²+(x₃-x)²+(x₄-x)²+(x₅-x)²)/5) Your program must contain at least the following functions: a function that calculates and returns the mean and a function that calculates the standard deviation. Format your output with setprecision(2) to ensure...
In Java please: 5.23 LAB: Seasons Write a program that takes a date as input and...
In Java please: 5.23 LAB: Seasons Write a program that takes a date as input and outputs the date's season. The input is a string to represent the month and an int to represent the day. Ex: If the input is: April 11 the output is: Spring In addition, check if the string and int are valid (an actual month and day). Ex: If the input is: Blue 65 the output is: Invalid The dates for each season are: Spring:...
Write a Python program which takes a set of positive numbers from the input and returns...
Write a Python program which takes a set of positive numbers from the input and returns the sum of the prime numbers in the given set. The sequence will be ended with a negative number.
Write a program that takes a date as input and outputs the date's season. The input...
Write a program that takes a date as input and outputs the date's season. The input is a string to represent the month and an int to represent the day. Ex: If the input is: April 11 the output is: Spring In addition, check if the string and int are valid (an actual month and day). Ex: If the input is: Blue 65 the output is: Invalid The dates for each season are: Spring: March 20 - June 20 Summer:...
Write a Java application with a JavaFXGUI that takes a String input by the user and...
Write a Java application with a JavaFXGUI that takes a String input by the user and shows whether the string contains all 26 letters of the (English version of the Latin) alphabet. For example, "Pack my box with five dozen liquor jugs" contains all 26 letters, but "The quick frown box jumps over the hazy log" does not contain a d. It does not matter whether one or more letters appear more than once. The GUI needs, at minimum, a...
Write a Java application with a JavaFXGUI that takes a String input by the user and...
Write a Java application with a JavaFXGUI that takes a String input by the user and shows whether the string contains all 26 letters of the (English version of the Latin) alphabet. For example, "Pack my box with five dozen liquor jugs" contains all 26 letters, but "The quick frown box jumps over the hazy log" does not contain a d. It does not matter whether one or more letters appear more than once. The GUI needs, at minimum, a...
Write a program that takes in a positive integer as input, and outputs a string of...
Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is: As long as x is greater than 0 Output x % 2 (remainder is either 0 or 1) x = x / 2 Note: The above algorithm outputs the 0's and 1's in reverse order. Ex: If the input is: 6 the output is: 011 6 in binary is...
IN PYTHON Write a program that takes in a positive integer as input, and outputs a...
IN PYTHON Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is: As long as x is greater than 0 Output x % 2 (remainder is either 0 or 1) x = x // 2 Note: The above algorithm outputs the 0's and 1's in reverse order. You will need to write a second function to reverse the string....
Write a program that takes in a line of text as input, and outputs that line...
Write a program that takes in a line of text as input, and outputs that line of text in reverse. The program repeats, ending when the user enters "Quit", "quit", or "q" for the line of text. Ex: If the input is: Hello there Hey quit then the output is: ereht olleH yeH IN C++ PLEASE!
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT