Anda di halaman 1dari 2

Nomor1 (Tugas2)

/*
* 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 Pengulangan;
import java.util.Scanner;

/**
*
* @author lenovo
*/
public class Tugas2 {
public static void main(String[]args){
int i;
Scanner userInput = new Scanner(System.in);
System.out.print("Anak Ayam Turun: ");
i = userInput.nextInt();
i = i-1;
for (int a=i; a>=3; a--){
System.out.println("Hilang Satu Tinggal "+a);
}
}
}

Nomor2 (Tugas4)
/*
* 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 Pengulangan;
import java.util.Scanner;

/**
*
* @author lenovo
*/
public class Tugas4 {
public static void main(String[]args){
int a;
Scanner userInput = new Scanner(System.in);
System.out.println("Masukkan Banyak Suku Deret : ");
a = userInput.nextInt();
int i = 1;
int jumlah = 0;
a=a-1;
while (i<=a){

jumlah=jumlah+i;
System.out.print(i+" + ");
i=i+1;

}
a=a+1;
jumlah=jumlah+a;
System.out.print(a);
System.out.println(" = "+jumlah);
}
}

Nomor3 (Tugas5)
/*
* 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 Pengulangan;
import java.util.*;
/**
*
* @author lenovo
*/
public class Tugas5 {
public static void main(String[] args ){
Scanner userInput = new Scanner(System.in);
char lagi;
int n;

int jumlah = 0;
int i = 1;
System.out.println("Pilih Y/T Untuk Memasukkan Sembarang Bilangan");
System.out.println("Untuk Memasukkan Bilangan Pilih Y; Untuk Berhenti
Pilih T");
do
{

System.out.print("Angka :");
n = userInput.nextInt();
jumlah = jumlah+n;
i++;

System.out.print("Lagi (Y/T) = ");


lagi = userInput.next().charAt(0);
}

while((lagi != 'T')&&(lagi== 'Y'));


System.out.println("");
System.out.println("Total Penjumlahan : "+jumlah);

}
}

Anda mungkin juga menyukai