Write a java program to convert temperature from fahrenheit


For this assignment, you will be modifying the exercises from the previous assignment.

Change them to use a keyboard scanner instead of hard-coding values.

Use the nextLine() and parsing technique

We need to use the scanner
import java.util.Scanner;

Then created a keyboard reader

Scanner keyboard = new Scanner(System.in)

Write a Java program to convert temperature from Fahrenheit to Celsius.
public static void main(String[] args) {
double fahrenheit = 123.45;
double celcius = ((5 * (fahrenheit - 32.0)) / 9.0);

System.out.println("Exercise #1");
System.out.println(fahrenheit + "F is " + celcius + "C");
Output:
Exercise #1
Enter Fahrenheit: 123.45
123.45F is 50.80555555555556C
Exercise 2
Write a Java program that converts inches to meters
Use double variables inches and meters.
(One inch is 0.0254 meters)
public static void main(String[] Strings) {

Scanner input = new Scanner(System.in);

System.out.print("Input a value for inch: ");
double inch = input.nextDouble();
double meters = inch * 0.0254;
System.out.println("Exercise #2");
System.out.println(inch + " inch is " + meters + " meters");
Output:
Enter inches: 1000.0
1000.0 inches are 25.4 meters
Exercise 3
Concatenate first, middle, and last name
Create 3 Strings (firstName, middleInitial, and lastName)
Create 4th String variable named fullName and use the + operator to concatenate all parts of the name into one full name.
The user will input the data.
Enter your first name: Johhn
Enter your middle initial: J
Enter your last name: Jose

The full name is: John J. Jose
public static void main(String[] args) {
String fullName = "John J. Jose";
String lastName = fullName.substring(14);
System.out.println("Exercise #3");
System.out.println( "The full name is " + fullName);
Write a Java program to demonstrate the Java arithmetic operators
Name the integer variables x and y. That's okay to have single letter variables for this small demonstration.
Input x and y from the keyboard
Write the appropriate code to give this output:
public static void main(String args[]) {
int x = 11;
int y = 5;
System.out.println("Exercise #4");
System.out.println("11 + 5 = " + (x + y) );
System.out.println("11 - 5 = " + (x - y) );
System.out.println("5 - 11 = " + (y - x) );
System.out.println("11 * 5 = " + (x * y) );
System.out.println("11 / 5 = " + (x / y) );
System.out.println("11 % 5 = " + (x % y) );
}
Sample
Enter x: 12
Enter y: 6

12 + 6 = 18
12 - 6 = 6
6 - 12 = -6
12 * 6 = 72
12 / 6 = 2
12 % 6 = 0

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Write a java program to convert temperature from fahrenheit
Reference No:- TGS02386880

Now Priced at $15 (50% Discount)

Recommended (98%)

Rated (4.3/5)