/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Matkul;
/**
*
* @author kumal
*/
public class M7_pangkatWhile {
public static void main(String[] args) {
java.util.Scanner input = new java.util.Scanner(System.in);
System.out.print("Masukkang angka: ");
int angka = input.nextInt();
System.out.print("Masukkang pangkat: ");
int pangkat = input.nextInt();
while (pangkat<0) {
System.out.print("Masukkan pangkat positif: ");
pangkat = input.nextInt();
}
int i=0;
while (i<=pangkat) {
int hasil = (int) Math.pow(angka, i);
System.out.println(angka + " ^ " + i + " = " + hasil);
i++;
}
}
}
Like this:
Like Loading...
Related