Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
24 views

Java Lab 2

The document outlines a Java lab assignment focused on variables and user input. It instructs students to create a program that converts feet to meters and Fahrenheit to Celsius using specific equations, while storing and printing the results as integer variables. Test values for both conversions are provided for validation.

Uploaded by

arya.santosh2007
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Java Lab 2

The document outlines a Java lab assignment focused on variables and user input. It instructs students to create a program that converts feet to meters and Fahrenheit to Celsius using specific equations, while storing and printing the results as integer variables. Test values for both conversions are provided for validation.

Uploaded by

arya.santosh2007
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Java Lab 2 – Variables and input

 Create a new Java file (empty Java file), save it to your H: drive, call it lab2
 Insert the following code to set up your program:

import java.util.Scanner;

public class lab2 {

public static void main (String args[]){

Scanner input = new Scanner(System.in);

int myFirstVariable = input.nextInt() //for an int


double mySecondVariable = input.nextDouble() //for a double

100pt (do both):


 Make a feet to metres converter using the following equation:

m = ft/3.28

Allow the user to enter the feet value. Store both the feet value and the answer as an
integer variable, and then print the answer.

 Make a Fahrenheit to Celsius calculator using the following equation:

C = (F – 32) * 5/9

Allow the user to enter the Fahrenheit value using the Scanner class. Store both the
Fahrenheit value and the answer as an integer variable, and then print the answer.
Test Values:

Fahrenheit Celcius
1 -17.22
100 37.77
-459.4 -273

Feet Meters
6 1.82
12 3.65
300.5 91.6

You might also like