Question

In: Computer Science

In a file called Conversions.java, write a program that: Asks the user to enter a double...

In a file called Conversions.java, write a program that:

Asks the user to enter a double number.

Stores that number into a variable called z.

Casts variable z into an integer, and stores the result into a variable called z1.

Creates a variable z2, and sets it equal to the integer closest to z.

Creates a variable z3, and sets it equal to the floor of z.

Creates a variable z4, and sets it equal to the ceiling of z.

Prints out the values of z1, z2, z3, z4, using the same format as shown below.

For example: if the user enters 3.9, your program output should look like this:

Please enter a double number: 3.9

z cast into an int becomes 3.

z rounded becomes 4.

The floor of z is 3.

The ceiling of z is 4.

Solutions

Expert Solution

w Java User Input (Scanner class X Online C++ Compiler - online ed x C in A File Called Conversionsjava, Java Examples Math Examples x + -ox → C onlinegdb.com/online_ct_compiler Run Debug Stop Stare Sive Dessulify Language Jeva OnlineGDB beta crne compless and debugger lor c++ Main.java code.comde.run. debug. share. DE 3 Welcome to GDB Online. 4 GDR online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl, 5 CN, VI, Swift, Pascal, Fortran, Ilaskell, objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog. 6 Code, Compile, Run and Debug online from anywhere in world. My Projects Learn Programming Programming Questions We are Hiring Sign Up 18 Login f y + 19.5K 9 import java.util.; 10 public class Conversions 11- public static void main(String[] args) { Scanner sc - new Scanner(System.in); double 2; System.out.print("Please enter a double number: "); z=5c.nextDouble(); int zl (int); int 22 - (int) Math.round(2); int z3 =(int)Math.floor(2); int 24-(int) Math.ceil(z); System.out.println("z cast into an int becomes "+z1); System.out.println("z rounded becomes " z2); System.out.println("The floor of z is "+z3); System.out.println("The ceiling of z is "+24); GOT AN OPINION? SHORE AND GET BALASE) Rakuten AP Have fun taking surveys and get paidi ADS VIA CARBON Please enter a double number:3.9 2 cart into an int. DACOMAR 3 2 rounded becomes The floor of z is 3 The ceiling of zis 4 About FACI Hog. Terms of Use Contact Us - GUH Tutorial - Credits 2016-2019 GDB Online ... Program finished with exit code 0 Pre ENTER LO exit 116.j Type here to search A G - 256 AM ENG 9/11/2019 21

w Java User Input (Scanner class X Online C++ Compiler - online ed x C in A File Called Conversionsjava, Java Examples Math Examples x + -ox → C onlinegdb.com/online_ct_compiler Run Debug Stop Stare Sive Dessulify Language Jeva OnlineGDB beta crne compless and debugger lor c++ Main.java code.comde.run. debug. share. DE 3 Welcome to GDB Online. 4 GDR online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl, 5 CN, VI, Swift, Pascal, Fortran, Ilaskell, objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog. 6 Code, Compile, Run and Debug online from anywhere in world. My Projects Learn Programming Programming Questions We are Hiring Sign Up 18 Login f y + 19.5K 9 import java.util.; 10 public class Conversions 11- public static void main(String[] args) { Scanner sc - new Scanner(System.in); double 2; System.out.print("Please enter a double number: "); z=5c.nextDouble(); int zl (int); int 22 - (int) Math.round(2); int z3 =(int)Math.floor(2); int 24-(int) Math.ceil(z); System.out.println("z cast into an int becomes "+z1); System.out.println("z rounded becomes " z2); System.out.println("The floor of z is "+z3); System.out.println("The ceiling of z is "+24); GOT AN OPINION? SHORE AND GET BALASE) Rakuten AP Have fun taking surveys and get paidi ADS VIA CARBON Please enter a double number:3.9 2 cart into an int. DACOMAR 3 2 rounded becomes The floor of z is 3 The ceiling of zis 4 About FACI Hog. Terms of Use Contact Us - GUH Tutorial - Credits 2016-2019 GDB Online ... Program finished with exit code 0 Pre ENTER LO exit 116.j Type here to search A G - 256 AM ENG 9/11/2019 21

We were unable to transcribe this image

w Java User Input (Scanner class X Online C++ Compiler - online ed x C in A File Called Conversionsjava, Java Examples Math Examples x + -ox → C onlinegdb.com/online_ct_compiler Run Debug Stop Stare Sive Dessulify Language Jeva OnlineGDB beta crne compless and debugger lor c++ Main.java code.comde.run. debug. share. DE 3 Welcome to GDB Online. 4 GDR online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl, 5 CN, VI, Swift, Pascal, Fortran, Ilaskell, objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog. 6 Code, Compile, Run and Debug online from anywhere in world. My Projects Learn Programming Programming Questions We are Hiring Sign Up 18 Login f y + 19.5K 9 import java.util.; 10 public class Conversions 11- public static void main(String[] args) { Scanner sc - new Scanner(System.in); double 2; System.out.print("Please enter a double number: "); z=5c.nextDouble(); int zl (int); int 22 - (int) Math.round(2); int z3 =(int)Math.floor(2); int 24-(int) Math.ceil(z); System.out.println("z cast into an int becomes "+z1); System.out.println("z rounded becomes " z2); System.out.println("The floor of z is "+z3); System.out.println("The ceiling of z is "+24); GOT AN OPINION? SHORE AND GET BALASE) Rakuten AP Have fun taking surveys and get paidi ADS VIA CARBON Please enter a double number:3.9 2 cart into an int. DACOMAR 3 2 rounded becomes The floor of z is 3 The ceiling of zis 4 About FACI Hog. Terms of Use Contact Us - GUH Tutorial - Credits 2016-2019 GDB Online ... Program finished with exit code 0 Pre ENTER LO exit 116.j Type here to search A G - 256 AM ENG 9/11/2019 21

4 1 import java.util.Scanner; 2 public class Main 3- { public static void main(String[] args) { 5 Scanner sc = new Scanner(System.in); double Z; 7 System.out.print("Please enter a double number:"); 8 z=sc.nextDouble(); 9 int z1=(int)z; 10 int z2 = (int) Math.round(z); int z3 =(int)Math.floor(z); 12 int z4=(int) Math.ceil(z); System.out.println("z cast into an int becomes "+z1); 14 System.out.println("z rounded becomes "+z2); System.out.println("The floor of z is "+z3); 16 System.out.println("The ceiling of z is "+24); 17 } 18 } 11 13 input Please enter a double number:3.9 Iz cast into an int becomes 3 z rounded becomes 4 The floor of z is 3 The ceiling of z is 4 ... Program finished with exit code o Press ENTER to exit console. I

import java.util.Scanner;
public class Conversions
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double z;
System.out.print("Please enter a double number:");
z=sc.nextDouble();
int z1=(int)z;
int z2 = (int) Math.round(z);
int z3 =(int)Math.floor(z);
int z4=(int) Math.ceil(z);
System.out.println("z cast into an int becomes "+z1);
System.out.println("z rounded becomes "+z2);
System.out.println("The floor of z is "+z3);
System.out.println("The ceiling of z is "+z4);
}
}


Related Solutions

In a file called LengthSum.java, write a program that: - Asks the user to enter a...
In a file called LengthSum.java, write a program that: - Asks the user to enter a string. - Asks the user to enter a second string. - Prints out the length of the first string, the length of the second string, and the sum of the two lengths, using EXACTLY the same format as shown below. For example: if the user enters strings "UT" and "Arlington", your program output should look EXACTLY like this: Please enter a string: UT Please...
In a file called LengthSum.java, write a program that: Asks the user to enter a string....
In a file called LengthSum.java, write a program that: Asks the user to enter a string. Asks the user to enter a second string. Prints out the length of the first string, the length of the second string, and the sum of the two lengths, using EXACTLY the same format as shown below. For example: if the user enters strings "UT" and "Arlington", your program output should look EXACTLY like this: Please enter a string: UT Please enter a second...
In a file called FourCapitalizations.java, write a program that: Asks the user to enter a string....
In a file called FourCapitalizations.java, write a program that: Asks the user to enter a string. Prints out four different versions of that string: The original version of the string. The upper-case version of the string. The lower-case version of the string. A version where the character at position 0 capitalized, and all other characters in lower case. For example: if the user enters string "gaNDalF12 !! AB3w", your program output should look EXACTLY like this: Please enter a string:...
In a file called DivisibilityTests.java, write a program that: Asks the user to enter an integer....
In a file called DivisibilityTests.java, write a program that: Asks the user to enter an integer. It is OK for your program to crash when the user does not enter a valid integer. If the integer is less than 0, the program prints: "The number is negative." If the integer is divisible by 2 and by 3, the program prints: "The number is even and divisible by 3." If the integer is divisible by 2 but not by 3, the...
In a file called ThreeOperations.java, write a program that: Asks the user to enter two real...
In a file called ThreeOperations.java, write a program that: Asks the user to enter two real numbers (doubles, not integers) called N1 and N2. It is OK if your program crashes when the user does not enter valid double numbers. Computes and displays the following operations between the two: multiplication, division, exponentiation. For the results of these two operations, only two decimal digits should be displayed. For example: if the user enters numbers 11 and 7, your program output should...
Write a program that asks the user to enter the name of a file, and then...
Write a program that asks the user to enter the name of a file, and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the file. Use Notepad or another text editor to create a sample file that can be used to test the program. Sample Run java FileLetterCounter Enter file name: wc4↵ Enter character to count: 0↵ The character '0' appears in the file...
Write a C program that asks the user to enter double values (the values can be...
Write a C program that asks the user to enter double values (the values can be positive, zero, or negative). After entering the first double value, the program asks "Would you like to enter another value?", and if the user enters Y or y, the program continues to get additional values and stores these values into a double array (for up to 100 values — use a symbolic #define constant to specify the 100 size limit). The program will need...
In a file called NumbersToMonths.java, write a program that: Asks the user to specify a month...
In a file called NumbersToMonths.java, write a program that: Asks the user to specify a month as an integer between 1 and 12. It is OK for your program to crash when the user does not enter a valid integer. Prints out the name of the corresponding month. Prints out "This number does not correspond to a month." if the integer is less than 1 or greater than 12. For example: if the user enters 1, your program output should...
ComputeAverage Write a class called ComputeAverage what it does: asks the user to enter three double...
ComputeAverage Write a class called ComputeAverage what it does: asks the user to enter three double numbers (see examples below), it uses Scanner class to read from standard input each one of the doubles entered by the user. it then prints the average of the three numbers. Suggested steps: 1. prompt the user to enter each of the three doubles by printing. 2. read each of the three doubles using a Scanner. Remember you need to declare a Scanner variable...
Write a program called Assignment3 (saved in a file Assignment3 .java) that asks a user to...
Write a program called Assignment3 (saved in a file Assignment3 .java) that asks a user to enter two strings. First, the program prompts: Please enter a string. The program should read in the string, and prompts: Please enter another string. The program reads in two strings and it prints a menu to the user. The program asks for user to enter an option and performs one of the following: Here are the options on the menu: Option a: checks if...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT