Question: Java Assignment 2 This assignment requires take the floor of the number, not round it. I need some help. Thank you. I have included my
Java Assignment 2
This assignment requires take the floor of the number, not round it. I need some help. Thank you. I have included my code below.
This assignment will focus on the use of arithematic operators. Casting will also be needed and will be described later in the assignment.
1. Create a Java program:
2. The class name for the program should be 'DecimalFloor'.
3. In the main method you should perform the following:
Create a Scanner object.
Input a decimal value using the Scanner object.
Round the input value down to the nearest integer (floor).
Output the value input.
Output the rounded value.
Pseudo flowchart for the assignment program:
1. Create a Scanner object using the Scanner class found in the java.util package.
2. Output a prompt asking the using to input a decimal value.
3. Accept the input value into a variable capable of holding decimal values.
4. Convert the decimal value to an integer value. This will drop all the decimal positions to the right of the decimal.
5. Covert the integer value to a double value.
6. Output the initial value input.
7. Output the rounded (floor) double value.
*******************************************************************************************
\\THIS IS MY CURRENT CODE
import java.util.Scanner;
public class DecimalFloor {
public static void main(String[] args) { //Create a Scanner object Scanner scan = new Scanner(System.in);
//Prompt the user to enter a number to round System.out.println("Enter the number to be rounded: ");
//Compute the rounded numerical value double num = scan.nextDouble(num);
//Display results System.out.println(); System.out.println(num + " after rounding is: " + Math.floor(num)); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
