Please use Notepad for write the program Numerals Programming Assignment Your pr
ID: 3886889 • Letter: P
Question
Please use Notepad for write the program Numerals Programming Assignment Your programming assignment is a step in the process toward the Roman Numeral generator. You must ask the user for a 4 digit number. Then you need to split the number into it's ones, tens, hundreds and thousands place values and display each value. (Hint: Simple modular arithmetic and division can get you your required result.) You must use mathematical expressions to split the four digit number into it's place values. An example output would look like this: Please enter a 4 digit number 1982 2 The one's place value is: The ten's place value is: The hundred's place value is: 9 The thousand's place value is:Explanation / Answer
package Online;
import java.util.Scanner;
//Class RomanNumeralGenerator definition
public class RomanNumeralGenerator
{
//Main method definition
public static void main(String Pyari[])
{
//Scanner class object created to accept a number from the user
Scanner sc = new Scanner(System.in);
//Accept a number from the user
System.out.println("Please enter a 4 digit number: ");
int num = sc.nextInt();
//Loops till number becomes zero
for(int c = 1; num != 0; num /= 10, c++)
{
//Switch - case begin
switch(c)
{
case 1:
System.out.printf("The one's place value is: %8d ", (num % 10));
break;
case 2:
System.out.printf("The ten's place value is: %8d ", (num % 10));
break;
case 3:
System.out.printf("The hundred's place value is: %4d ", (num % 10));
break;
case 4:
System.out.printf("The thousand's place value is: %3d ", (num % 10));
break;
}//End of switch case
}//End of for loop
}//End of main method
}//End of class
Sample Run 1:
Please enter a 4 digit number: 1982
The one's place value is: 2
The ten's place value is: 8
The hundred's place value is: 9
The thousand's place value is: 1
Sample Run 2:
Please enter a 4 digit number: 9532
The one's place value is: 2
The ten's place value is: 3
The hundred's place value is: 5
The thousand's place value is: 9