-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfloat_to_whole.java
More file actions
31 lines (20 loc) · 898 Bytes
/
float_to_whole.java
File metadata and controls
31 lines (20 loc) · 898 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import java.util.Random;
//import java.util.Scanner;
public class float_to_whole {
/*
Program that reads a floating point value (double) and prints the closest whole numbers less
than and greater than that value.
For example, if the number is 28.466, the program would print 28 and 29.
*/
public static void main(String[] args) {
Random generator = new Random() ;
float Number1;
Number1 = generator.nextFloat() * 30;
// Scanner MyNumber = new Scanner(System.in);
// System.out.println("Enter Float Number");
//Number1 = MyNumber.nextFloat();
System.out.println("largest number is" + " " + ((int)Number1 + 1) ); //increment
System.out.println("float number is" + Number1);
System.out.println("smallest number is" + " " + ((int)Number1 - 1) ); //decrement
}
}