Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Chapter 2: 1. public class Exercise02_01 { // Main method public static void main(String[] args) { java.util.Scanner input = new java.util.Scanner(System.in); // Enter a temperature in Celsius System.out.print("Enter a temperature in Celsius: "); double celsius = input.nextDouble(); // Convert it to Fahrenheit double fahrenheit = (9.0 / 5) * celsius + 32; // Display the result System.out.println(celsius + " Celsius is " + fahrenheit + " Fahrenheit"); } } 5. public class Exercise02_05 { public static void main(String args[]) { // Read subtotal java.util.Scanner input = new java.util.Scanner(System.in); System.out.print("Enter subtotal and gratuity rate: "); double subtotal = input.nextDouble(); double rate = input.nextDouble(); double gratuity = subtotal * rate / 100; double total = subtotal + gratuity; System.out.println("The gratuity is " + gratuity + " total is " + total); } } 13. import java.util.Scanner; public class Exercise02_13 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter monthly saving amount: "); double monthlyDeposit = input.nextDouble(); double currentValue = monthlyDeposit; // First month value currentValue = currentValue * (1 + 0.00417); System.out.println("After the first month, the account value is " + currentValue); // Second month value currentValue = (currentValue + monthlyDeposit) * (1 + 0.05 / 12); System.out.println("After the second month, the account value is " + currentValue); // Third month value currentValue = (currentValue + monthlyDeposit) * (1 + 0.05 / 12); System.out.println("After the third month, the account value is " + currentValue); // Fourth month value currentValue = (currentValue + monthlyDeposit) * (1 + 0.05 / 12); // Fifth month value currentValue = (currentValue + monthlyDeposit) * (1 + 0.05 / 12); // Sixth month value currentValue = (currentValue + monthlyDeposit) * (1 + 0.05 / 12); System.out.println("After the sixth month, the account value is " + currentValue); } } 23. import java.util.Scanner; public class Exercise02_23 { public static void main(String args[]) { Scanner input = new Scanner(System.in); System.out.print("Enter the driving distance: "); double distance = input.nextDouble(); System.out.print("Enter miles per gallon: "); double milesPerGallon = input.nextDouble(); System.out.print("Enter price per gallon: "); double pricePerGallon = input.nextDouble(); System.out.println("The cost of driving is $" + (distance / milesPerGallon) * pricePerGallon); } }