SHARE
TWEET

Untitled

a guest Sep 20th, 2019 87 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ################PERPANGKATAN######
  2. ###ForLoop
  3. import java.util.Scanner;
  4. public class ForPangkat {
  5. public static void main(String[ ] args){
  6. int hasil = 1;
  7. int angka, pangkat;
  8.    
  9.     Scanner a=new Scanner(System.in);
  10.     System.out.print("Masukkan angka: ");
  11.     angka=a.nextInt();
  12.    
  13.     System.out.print("Masukkan pangkat: ");
  14.     Scanner b=new Scanner(System.in);
  15.     pangkat=b.nextInt();
  16.  
  17.  
  18.         for(int i=1;i<=pangkat;i++){
  19.        
  20.         hasil=hasil*angka;
  21.     }
  22.  
  23.  
  24.     System.out.println( "Hasil "+angka+" pangkat "+pangkat+" = " +hasil);
  25.  
  26.  
  27. }
  28. }  
  29.  
  30. ###While-Pangkat
  31. import java.util.Scanner;
  32.  
  33. public class WhilePangkat {
  34.  
  35. public static void main(String[] args) {
  36.  Scanner b = new Scanner(System.in);
  37.  System.out.println("masukkan angka : ");
  38.  int input = b.nextInt();
  39.  
  40.  System.out.println("masukkan pangkat : ");
  41.  int pangkat = b.nextInt();
  42.  
  43.  int i = 1;
  44.  int h = 1;
  45.  
  46.  while (i<pangkat){
  47.  h = h*input;
  48.  i++;
  49.  }
  50.  System.out.println(input + " ^ " +pangkat +" = " +h);
  51.  
  52.  }
  53.  
  54. }
  55.  
  56.  
  57. ###DO
  58. import java.util.Scanner;
  59.  
  60. public class PangkatDo {
  61.  public static void main(String[] args) {
  62.  Scanner input = new Scanner(System.in);
  63.  System.out.println("masukkan angka : ");
  64.  int angka = input.nextInt();
  65.  System.out.println("masukkan pangkat : ");
  66.  int pangkat = input.nextInt();
  67.  
  68.  int i = 1;
  69.  int h = 1;
  70.  
  71.  do {
  72.  h = h*angka;
  73.  i++ ;
  74.  }while(i<pangkat);
  75.  System.out.println(angka +" ^ " + pangkat + " = " +h);
  76. }
  77.  }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top