Sekedar buat referensi membuat program menggunakan Java kali ini admin memberikan contoh pembuatan Konversi suhu dengan menggunakan Java, Silahkan di simak,
Syntax Program
import java.util.Scanner;
/**
*
* @author agrikuswandani
*/
public class SwitchCase {
public static void layarUtama(){
System.out.println("\n\t*----MENU----*");
System.out.println("1. Dari Celcius");
System.out.println("2. Dari Fahrenheit");
System.out.println("3. Dari Kelvin");
System.out.println("4. Dari Reamur");
System.out.println("5. X-it");
int n;
double c, r, f, k;
Scanner x = new Scanner(System.in);
System.out.print("Masukkan pilihan : ");
n = x.nextInt();
switch(n){
case 1:
System.out.print("Masukkan Derajat Celcius : ");
c = x.nextDouble();
k = c + 273.15;
f = c * 1.8 + 32;
r = c * 0.8;
System.out.println(c+" Celcius = "+k+" Kelvin");
System.out.println(c+" Celcius = "+f+" Fahrenheit");
System.out.println(c+" Celcius = "+r+" Reamur");
layarUtama();
break;
case 2:
System.out.print("Masukkan Derajat Fahrenheit : ");
f = x.nextDouble();
c = (f - 32) / 1.8;
k = (f + 459.67) / 1.8;
r = (f - 32) / 2.25;
System.out.println(f+" Fahrenheit = "+k+" Kelvin");
System.out.println(f+" Fahrenheit = "+c+" Celcius");
System.out.println(f+" Fahrenheit = "+r+" Reamur");
layarUtama();
break;
case 3:
System.out.print("Masukkan Derajat Kelvin : ");
k = x.nextDouble();
f = (k * 1.8) - 459.67;
r = (k - 273.15) * 0.8;
c = k - 273.15;
System.out.println(k+" Kelvin = "+f+" Fahrenheit");
System.out.println(k+" Kelvin = "+r+" Reamur");
System.out.println(k+" Kelvin = "+c+" Celcius");
layarUtama();
break;
case 4:
System.out.print("Masukkan Derajat Reamur : ");
r = x.nextDouble();
f = (r * 2.25) + 32;
k = (r / 0.8) + 273.15;
c = r/ 0.8;
System.out.println(r+" Reamur = "+f+" Fahrenheit");
System.out.println(r+" Reamur = "+k+" Kelvin");
System.out.println(r+" Reamur = "+c+" Celcius");
layarUtama();
break;
case 5:
break;
default:
System.out.println("Maaf, tolong masukkan pilihan 1 - 4");
layarUtama();
}
}
public static void main(String[] args) {
layarUtama();
}
}
Program Konversi Suhu Dengan JAVA |
Syntax Program
import java.util.Scanner;
/**
*
* @author agrikuswandani
*/
public class SwitchCase {
public static void layarUtama(){
System.out.println("\n\t*----MENU----*");
System.out.println("1. Dari Celcius");
System.out.println("2. Dari Fahrenheit");
System.out.println("3. Dari Kelvin");
System.out.println("4. Dari Reamur");
System.out.println("5. X-it");
int n;
double c, r, f, k;
Scanner x = new Scanner(System.in);
System.out.print("Masukkan pilihan : ");
n = x.nextInt();
switch(n){
case 1:
System.out.print("Masukkan Derajat Celcius : ");
c = x.nextDouble();
k = c + 273.15;
f = c * 1.8 + 32;
r = c * 0.8;
System.out.println(c+" Celcius = "+k+" Kelvin");
System.out.println(c+" Celcius = "+f+" Fahrenheit");
System.out.println(c+" Celcius = "+r+" Reamur");
layarUtama();
break;
case 2:
System.out.print("Masukkan Derajat Fahrenheit : ");
f = x.nextDouble();
c = (f - 32) / 1.8;
k = (f + 459.67) / 1.8;
r = (f - 32) / 2.25;
System.out.println(f+" Fahrenheit = "+k+" Kelvin");
System.out.println(f+" Fahrenheit = "+c+" Celcius");
System.out.println(f+" Fahrenheit = "+r+" Reamur");
layarUtama();
break;
case 3:
System.out.print("Masukkan Derajat Kelvin : ");
k = x.nextDouble();
f = (k * 1.8) - 459.67;
r = (k - 273.15) * 0.8;
c = k - 273.15;
System.out.println(k+" Kelvin = "+f+" Fahrenheit");
System.out.println(k+" Kelvin = "+r+" Reamur");
System.out.println(k+" Kelvin = "+c+" Celcius");
layarUtama();
break;
case 4:
System.out.print("Masukkan Derajat Reamur : ");
r = x.nextDouble();
f = (r * 2.25) + 32;
k = (r / 0.8) + 273.15;
c = r/ 0.8;
System.out.println(r+" Reamur = "+f+" Fahrenheit");
System.out.println(r+" Reamur = "+k+" Kelvin");
System.out.println(r+" Reamur = "+c+" Celcius");
layarUtama();
break;
case 5:
break;
default:
System.out.println("Maaf, tolong masukkan pilihan 1 - 4");
layarUtama();
}
}
public static void main(String[] args) {
layarUtama();
}
}
0 komentar
Posting Komentar