import java.util.Scanner;
public class menu{
public static void main (String [] args){
Scanner input= new Scanner(System.in);
garis();
System.out.println(" MENU PILIHAN ");
garis();
System.out.println("1. Menghitung rata - rata");
System.out.println("");
System.out.println("2. Menghitung bilangan kelipatan 4");
System.out.println("");
garis();
System.out.println("Anda pilih nomor :");
int pil=input.nextInt();
switch (pil){
case 1:{
System.out.println(" Menghitung rata - rata");
System.out.println("Masukan jumlah data :");
int n=input.nextInt();
int[]data=new int[10];
for(int i=1;i<=n;i++){
System.out.println("Data ke"+i+"=");
data[i]=input.nextInt();
}
int jum=0;
for(int i=1;i<=n;i++){
jum=jum+data[i];
}
System.out.println("Jumlah =" +jum);
int rata=jum/n;
System.out.println("Rata rata =" +rata);
break;
}
case 2:{
System.out.println("Menghitung keliapatan 4");
System.out.println("Dari =");
int nilai_awal=input.nextInt();
System.out.println("Sampai =");
int nilai_akhir=input.nextInt();
for (int i=nilai_awal; i<=nilai_akhir;i++){
if (i%4==0){
System.out.println(i);
}
}
break;
}
default:System.exit(0);
}}
static void garis(){
System.out.println("--------------------------");
}
}
public class menu{
public static void main (String [] args){
Scanner input= new Scanner(System.in);
garis();
System.out.println(" MENU PILIHAN ");
garis();
System.out.println("1. Menghitung rata - rata");
System.out.println("");
System.out.println("2. Menghitung bilangan kelipatan 4");
System.out.println("");
garis();
System.out.println("Anda pilih nomor :");
int pil=input.nextInt();
switch (pil){
case 1:{
System.out.println(" Menghitung rata - rata");
System.out.println("Masukan jumlah data :");
int n=input.nextInt();
int[]data=new int[10];
for(int i=1;i<=n;i++){
System.out.println("Data ke"+i+"=");
data[i]=input.nextInt();
}
int jum=0;
for(int i=1;i<=n;i++){
jum=jum+data[i];
}
System.out.println("Jumlah =" +jum);
int rata=jum/n;
System.out.println("Rata rata =" +rata);
break;
}
case 2:{
System.out.println("Menghitung keliapatan 4");
System.out.println("Dari =");
int nilai_awal=input.nextInt();
System.out.println("Sampai =");
int nilai_akhir=input.nextInt();
for (int i=nilai_awal; i<=nilai_akhir;i++){
if (i%4==0){
System.out.println(i);
}
}
break;
}
default:System.exit(0);
}}
static void garis(){
System.out.println("--------------------------");
}
}
Tidak ada komentar:
Posting Komentar