164k views
14 votes
Follow the directions below to submit Assignment 2:

Create a Java program.
The class name for the program should be 'DecimalFloor'.
In the main method you should perform the following:
Create a Scanner object.
Input a decimal /double value using the Scanner object.
Convert the input decimal/double value to an integer value (this will drop the decimal from the decimal/double value input).
Output the decimal/double value input.
Output the double/decimal value after converting the integer value back to a decimal value.
Pseudo flowchart for the assignment program:
Create a Scanner object using the Scanner class found in the java.util package.
Output a prompt asking the using to input a decimal value.
Accept the input value into a variable capable of holding decimal values.
Convert the decimal value to an integer value. This will drop all the decimal positions to the right of the decimal.
Covert the integer value to a double value.
Output the initial decimal value input.
Output the double value from step 5.

User Jamyn
by
3.2k points

1 Answer

6 votes

Answer:

Step-by-step explanation:

The following code is written in Java and performs every action requested in the question. Instead of converting back and forth it saves the decimal/double value in one variable and the integer value in another variable so both can easily be accessed and printed.

import java.util.Scanner;

public class DecimalFloor {

public static void main(String args[]) {

//Ask for input and place into variable decimalValue

Scanner in = new Scanner(System.in);

System.out.println("Input decimal value:");

double decimalValue = in.nextDouble();

//Rounding down decimalValue to integer

int integerValue = (int) Math.floor(decimalValue);

//Print both integerValue and decimalValue

System.out.println(integerValue);

System.out.println(decimalValue);

}

}

User Biotox
by
3.7k points