public class CobaAnakAyam {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int ayam, a=1;
System.out.print("Masukan angka = ");
ayam= input.nextInt();
if (ayam>=1 && ayam<=100000) {
while (ayam>a){
System.out.print("Anak ayam turun "+ayam+", hilang "+a);
ayam=ayam-a;
System.out.println(" tinggal "+ayam);
a=a+1;
if (ayam<=a){
System.out.println("Anak ayam turun "+ayam+", hilang "+ayam+" tinggal induknya");
break;
}
}
}
else {System.out.println("Angka harus antara 1 sampai 100.000");
}
}
}
0 comments:
Post a Comment