Question

In: Computer Science

This is a Java program Problem Description Write an application that inputs five digits from the...

This is a Java program

Problem Description

Write an application that inputs five digits from the user, assembles the individual digits into a five-digit integer number (the first digit is for one’s place, the second digit is for the ten’s place, etc.) using arithmetic calculations and prints the number. Assume that the user enters enough digits.

Sample Output

Enter five digits: 1 2 3 4 5

The number is 54321

Problem-Solving Tips

  1. The input digits are integer, so you will use int variables to represent them.
  2. You will need a series of statements to assemble the individual digits into the number, using integer arithmetic calculations.
  3. You should create a main class using JCreator and name your program as

Project1_ AssembleDigits_YourName.java

  1. Be sure to follow the spacing and indentation conventions shown in class.
  2. You should answer the follow-up questions in a separated Word document and name it

Project1_Answers_YourName.docx.

  1. If you have any questions as you proceed, ask your instructor for assistance.

Follow-Up Questions and Activities

  1. What are the results of the following expressions?
    1. 24 / 5 =
    2. 18 % 3 =
    3. 6+13 % 9 =
    4. 13 / 2 % 2 =
  2. What happens when the user inputs the following five digits: 1 76 3 9 5?

Problem Description

Write an application that inputs five digits from the user, assembles the individual digits into a five-digit integer number (the first digit is for one’s place, the second digit is for the ten’s place, etc.) using arithmetic calculations and prints the number. Assume that the user enters enough digits.

Sample Output

Enter five digits: 1 2 3 4 5

The number is 54321

Problem-Solving Tips

  1. The input digits are integer, so you will use int variables to represent them.
  2. You will need a series of statements to assemble the individual digits into the number, using integer arithmetic calculations.
  3. You should create a main class using JCreator and name your program as

Project1_ AssembleDigits_YourName.java

  1. Be sure to follow the spacing and indentation conventions shown in class.
  2. You should answer the follow-up questions in a separated Word document and name it

Project1_Answers_YourName.docx.

  1. If you have any questions as you proceed, ask your instructor for assistance.

Follow-Up Questions and Activities

  1. What are the results of the following expressions?
    1. 24 / 5 =
    2. 18 % 3 =
    3. 6+13 % 9 =
    4. 13 / 2 % 2 =
  2. What happens when the user inputs the following five digits: 1 76 3 9 5?

Solutions

Expert Solution

Project1_ AssembleDigits_YourName.java

import java.util.Scanner;

public class Project1_AssembleDigits_YourName {
   public static void main(String[] args) {
       // Scanner class object to get the input from user
       Scanner input=new Scanner(System.in);
       System.out.print("Enter five digits: ");
       // accept five digits from user
       int one=input.nextInt();
       int two=input.nextInt();
       int three=input.nextInt();
       int four=input.nextInt();
       int five=input.nextInt();
       // calculate the number
       int number=one+(two*10)+(three*100)+(four*1000)+(five*10000);
       System.out.println("The number is "+number); // print the number
       input.close(); // close Scanner object
   }
}

Sample run 1

Sample run 2


Related Solutions

Write a Java program to implement a Single Linked List that will take inputs from a...
Write a Java program to implement a Single Linked List that will take inputs from a user as Student Names. First, add Brian and Larry to the newly created linked list and print the output Add "Kathy" to index 1 of the linked list and print output Now add "Chris" to the start of the list and "Briana" to the end of the list using built-in Java functions. Print the output of the linked list.
JAVA 1. Write an application that inputs a telephone number as a string in the form...
JAVA 1. Write an application that inputs a telephone number as a string in the form (555) 555-5555. The application should use String method split to extract the area code as a token, the first three digits of the phone number as a token and the last four digits of the phone number as a token. The seven digits of the phone number should be concatenated into one string. Both the area code and the phone number should be printed....
IN JAVA: Write a simple program that takes 5 inputs from the user and save them...
IN JAVA: Write a simple program that takes 5 inputs from the user and save them into a Text File. The inputs are Student Name, Student Address and student Date of Birth. Also write a simple program that reads and display the input from the first program text file.
Java Program Problem // Description: Read five positive integers and average them. // Enter a negative...
Java Program Problem // Description: Read five positive integers and average them. // Enter a negative integer to end the program. import java.util.Scanner; public class Lab5 { public static void main (String args[]) {        Scanner sc;        sc = new Scanner(System.in);    final int MAX_NUMS = 5;        int num;       // variable to store the number        int sum;   // variable to store the sum        int count;    // variable to store...
JAVA Project: Student Major and status Problem Description: Write a program that prompts the user to...
JAVA Project: Student Major and status Problem Description: Write a program that prompts the user to enter two characters and displays the major and status represented in the characters. The first character indicates the major and the second is a number character 1, 2, 3 or 4, which indicates whether a student is a freshman, a sophomore, junior or senior. Suppose the following characters are used to denote the majors: M: Mathematics C: Computer Science I: Information Technology Here is...
Tokenizing Telephone Numbers Write java application that inputs a telephone number as a string in the...
Tokenizing Telephone Numbers Write java application that inputs a telephone number as a string in the form (555) 555-5555. The application should use String method split to extract the area code as a token, the first three digits of the phone number as a token and the last four digits of the phone number as a token. The seven digits of the phone number should be concatenated into one string. Both the area code and the phone number should be...
Develop a Java program for this problem where the user inputs an Earth age and the...
Develop a Java program for this problem where the user inputs an Earth age and the program will then display the age on Mercury, Venus, Jupiter, and Saturn. The values for d are listed in the table. Planet d = Approximate Number of Earth Days for This Planet to Travel Around the Sun Mercury 88 Venus 225 Jupiter 4380 Saturn 10767
Write a Java program that will add the digits of a person’s birth date to obtain...
Write a Java program that will add the digits of a person’s birth date to obtain a single digit to generate a numerology number. Write one separate method for each of the following tasks (it goes w/o saying that you will have a main() method along with these): date validating date crunching First: Get a Date Numerology has been used since ancient times to shed light on relationships, health, and global events. Each element in a birth date is believed...
Write a java program that uses a stack to reverse an integer of three digits. The...
Write a java program that uses a stack to reverse an integer of three digits. The program must prompt the user to input an integer of 3 digits and display it in reverse. - Your program must include the Stack class, the Reverse class, and the Test class. - In the Test class, the program must prompt the user to input a 3-digit number and display it in reverse. - Class Reverse must use the Stack class to reverse the...
Write a Java program for RSA encryption that has the following inputs and outputs: Given a...
Write a Java program for RSA encryption that has the following inputs and outputs: Given a message and an integer n = pq where p and q are odd primes and an integer e > 1 relatively prime to (p − 1)(q − 1), encrypt the message using the RSA cryptosystem with key (n, e).
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT