Lab2_sol - double volume = radius * radius * 3.14159 *...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CSE 114 Lab 2 2. Liang page 63, programming exercise 2.1. public class Exercise2_1 { // Main method public static void main(String[] args) { java.util.Scanner input = new java.util.Scanner(System.in); // Enter a temperature in Fahrenheit System.out.print("Enter a temperature in Celsius: "); double celsius = input.nextDouble(); // Convert it to Celsius double fahrenheit = (9.0 / 5) * celsius + 32; // Display the result System.out.println(celsius + " Celsius is " + fahrenheit + " Fahrenheit"); } } 3. Liang page 63, programming exercise 2.2. import java.util.Scanner; public class Exercise2_2 { public static void main(String[] args) { Scanner input = new Scanner(System.in); // Enter radius of the cylinder System.out.print("Enter radius of the cylinder: "); double radius = input.nextDouble(); // Enter length of the cylinder System.out.print("Enter length of the cylinder: "); double length = input.nextDouble();
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: double volume = radius * radius * 3.14159 * length; System.out.println("The volume of the cylinder is " + volume); } } 4. Liang page 64, programming exercise 2.3. public class Exercise2_3 { public static void main(String args) { // Enter foot java.util.Scanner input = new java.util.Scanner(System.in); System.out.print("Enter a value for feet: "); double feet = input.nextDouble(); double meter = feet * 0.305; System.out.println(feet + " feet is " + meter + " meters"); } } 5. Liang page 64, programming exercise 2.4. public class Exercise2_4 { public static void main(String args) { // Prompt the input java.util.Scanner input = new java.util.Scanner(System.in); System.out.print("Enter a number in pounds: "); double pounds = input.nextDouble(); double kilograms = pounds * 0.454; System.out.println(pounds + " pounds is " + kilograms + " kilograms"); } }...
View Full Document

Page1 / 2

Lab2_sol - double volume = radius * radius * 3.14159 *...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online