Write a program that declares and initializes a double variable. Then, round that number to the nearest whole number. Finally, multiply that new number by two and print it out. Challenge: use a Scanner to read in the initial double number from the user.
top of page
bottom of page
class Main { public static void main(String[] args) { double a = 7.5; long a2 = Math.round(a); double a3 = a2 * 2; System.out.println(a3); } }
class Main {
public static void main(String[] args) {
double mynumber = 6.89;
long mynumber2 = Math.round(mynumber);
double mynumber3 = mynumber2 * 2;
System.out.println(mynumber3);
}
}
import java.util.Scanner; class Main { public static void main(String[] args) { Scanner x = new Scanner(System.in); double y = x.nextDouble(); long r = Math.round(y); long o = r*2; System.out.println(o); } }
I'm not sure about the scanner, but here is my code: import java.lang.Math; class Main { public static void main(String[] args) { double num2 = 5.5; long num3 = Math.round(num2); double num4 = num3 * 2; System.out.println(num4); } }