Anda di halaman 1dari 2

import javax.swing.

JOptionPane; public class pangkat_dowhile{ public static void main(String[ ] args){ int hasil = 1; String x = ""; String y = ""; x = JOptionPane.showInputDialog("Masukkan angka"); int angka = Integer.valueOf(x).intValue(); y = JOptionPane.showInputDialog("Masukkan pangkat"); int pangkat = Integer.valueOf(y).intValue(); int i=1; do{ i++; hasil=hasil*angka; }while(i<=pangkat); String st3 = angka + " pangkat " + pangkat + " = " + hasil; JOptionPane.showMessageDialog(null, st3); } } public class cetak100kali_dowhile { public static void main(String[]args){ int a; a=1; do{ System.out.print("haris\n"); a++; }while (a<100); } } import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; public class baca_bilangan_ifelse{ public static void main(String[] args) { BufferedReader dataIn=new BufferedReader(new InputStreamReader(System.in)); String angka=""; System.out.print("Masukan angka: "); try{ angka=dataIn.readLine(); }catch(IOException e){ System.out.println(""); } if(Integer.parseInt(angka) == 1){ System.out.println("SATU"); } else if(Integer.parseInt(angka)== 2){ System.out.println("DUA"); } else if(Integer.parseInt(angka)== 3){ System.out.println("TIGA"); } else if(Integer.parseInt(angka) == 4){ System.out.println("EMPAT"); } else if(Integer.parseInt(angka) == 5){ System.out.println("LIMA"); }

else if(Integer.parseInt(angka) == 6){ System.out.println("ENAM"); } else if(Integer.parseInt(angka) == 7){ System.out.println("TUJUH"); } else if(Integer.parseInt(angka) == 8){ System.out.println("DELAPAN"); } else if(Integer.parseInt(angka) == 9){ System.out.println("SEMBILAN"); } else if(Integer.parseInt(angka) == 10){ System.out.println("SEPULUH"); } else{ System.out.println("Invalid number"); } } } import javax.swing.JOptionPane; public class ratarata_joption { public static void main(String[] args) { String nilai1=""; String nilai2=""; String nilai3=""; nilai1= JOptionPane.showInputDialog("Nilai 1:"); nilai2= JOptionPane.showInputDialog("Nilai 2:"); nilai3= JOptionPane.showInputDialog("Nilai 3:"); try{ int x = Integer.parseInt(nilai1); int y = Integer.parseInt(nilai2); int z = Integer.parseInt(nilai3); int jumlah = x + y +z; int rata = jumlah / 3; String msg = "Rata-Rata = " + rata ; if(rata>=60){ JOptionPane.showMessageDialog(null, msg + " :-)" ); } else { JOptionPane.showMessageDialog(null, msg + " :-( "); } }catch(NumberFormatException nfe){ String msg ="Data tidak dapat diproses!"; JOptionPane.showMessageDialog(null, msg ); } } }