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

Java Palindrome (Timelimit: 10seconds) Problem Description Write a Java program to solve the following problem. A...
Java Palindrome (Timelimit: 10seconds) Problem Description Write a Java program to solve the following problem. A palindromic number is an integer that is the same when the digits are reversed. For example, 121 and 625526 are palindromic, but 625 is not a palindromic number. Input: The input is in ‘palindrome.txt’. The first line of the input contains the line count m (1 ≤ m ≤ 1,000), which is the number of lines that follows the first line. Each of the...
Java Recursion (Timelimit: 3 seconds) Problem Description Write a Java program to solve the following problem....
Java Recursion (Timelimit: 3 seconds) Problem Description Write a Java program to solve the following problem. Recursion may appear in various contexts and in different forms. For fast implementation, we should always aim at transforming recursions into a simpler form of computation. In this assignment, the task is to evaluate X(·), which is defined as follows:               |0,if m = 0 or n = 0               | X(m,n−1),if n is odd and m is even X(m,n) = | X(m−1,n),if m...
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....
Java Collatz Conjecture (Timelimit: 3 seconds) Problem Description Write a Java program to solve the following...
Java Collatz Conjecture (Timelimit: 3 seconds) Problem Description Write a Java program to solve the following problem. The Collatz conjecture is about a sequence: start with any positive integer n. Then each term is obtained from the previous term as follows: if the previous term is even, the next term is one half the previous term. If the previous term is odd, the next term is 3 times the previous term plus 1. The conjecture is that no matter what...
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...
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 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
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT