Minggu, 30 Desember 2012

Perulangan java while do

perulangan 1:
int i=1 ;
do{
System.out.println(i) ;
i++ ;
}while( i != 11);
}
}


Perulangan 2:
import java.io.* ;
class loop4{
public static void main(String Arg[]) throws IOException {
int pil, l, s, r, p ;
double ls, vol ;
String str ;
BufferedReader Get=new BufferedReader(new InputStreamReader(System.in)) ;
do{
System.out.println(“Menu Utama”) ;
System.out.println(“1. Hitung Volume Kubus”) ;
System.out.println(“2. Hitung Luas”) ;
System.out.println(“3. Hitung LUas Lingkaran”) ;
System.out.println(“4. Keluar Program”) ;
System.out.print(“Pilihan Anda : “) ; str = Get.readLine() ;
pil = Integer.parseInt(str) ;
switch(pil){
case 1 :
System.out.println(“Menghitung Volume Kubus”) ;
System.out.print(“Sisi : “) ; str = Get.readLine() ;
s = Integer.parseInt(str) ;
vol = s * s * s ;
System.out.println(“Volume Kubus : ” + vol) ;
break ;
case 2 :
System.out.println(“Menghitung Luas Persegi Panjang”) ;
System.out.print(“Lebar   : “) ; str = Get.readLine() ;
l = Integer.parseInt(str) ;
System.out.print(“Panjang : “) ; str = Get.readLine() ;
p = Integer.parseInt(str) ;
ls = p * l ;
System.out.println(“Luas Persegi Panjang : ” + ls) ;
break ;
case 3 :
System.out.println(“Menghitung Luas Lingkaran”) ;
System.out.print(“Jari Jari   : “) ; str = Get.readLine() ;
r = Integer.parseInt(str) ;
ls = 3.14 * r * r ;
System.out.print(“Luas Lingkaran : ” + ls) ;
break ;
}
str = Get.readLine() ;
} while( pil != 4) ;
}
}



Tidak ada komentar:

Posting Komentar