-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathLab3.java
More file actions
35 lines (30 loc) · 1.15 KB
/
Lab3.java
File metadata and controls
35 lines (30 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
in this project we will be converting fahrenheit to centigrade
also, we will output the first 40 temperature measurements counting
by 5 using a FOR LOOP and WHILE LOOP
*/
public class Lab3 {
public static void main(String[] args){
float fahrenheit, centigrade;
fahrenheit = (float)98.6;
// to convert fahrenheit to centigrade is c=5/9 (f-32)
centigrade = (float)5/9*(fahrenheit-32);
//System.out.println("The convertion of " + fahrenheit + " degrees fahrenheit to centigrades is " + centigrade);
System.out.println(" ");
System.out.println("---------------FOR LOOP EXAMPLE--------------");
for (float i=0; i<=40.0; i+=5.0){
fahrenheit = (float) i;
centigrade = (float)5/9*(fahrenheit-32);
System.out.println("Fahrenheit: "+fahrenheit+" \t"+"Centigrade: " +centigrade);
}
System.out.println(" ");
System.out.println("--------------WHILE LOOP EXAMPLE-------------");
float count=0;
while(count <= 40){
fahrenheit = count;
centigrade = (float)5/9*(fahrenheit-32);
System.out.println("Fahrenheit: "+fahrenheit+" \t"+"Centigrade: " +centigrade);
count+=5.0;
}
}
}