public class Fungsi
{
public static void jumlah()
{
System.out.println("Dalam Fungsi jumlah");
int a = 7, b= 15, c= a+b;
System.out.println("a + b = " +c);
}
public static void main(String args[]){
jumlah();
}
}
import java.util.Scanner;
public class Fungsi1
{
public static void jumlah()
{
System.out.println("Anda memilih Fugsi Jumlah");
int a = 7, b= 15, c= a+b;
System.out.println("a + b = " +c);
}
public static void kurang()
{
System.out.println("Dalam Fugsi Kurang");
int a = 7, b= 15, c= a-b;
System.out.println("a - b = " +c);
}
public static void kali()
{
System.out.println("Dalam Fugsi Kali");
int a = 7, b= 15, c=a*b;
System.out.println("a * b = " +c);
}
public static void bagi()
{
System.out.println("Dalam Fugsi Bagi");
double a = 7, b= 15, c= a/b;
System.out.println("a/b= " + c );
}
public static void main(String args[])
{
Scanner masuk = new Scanner(System.in);
System.out.println("====== pilihan program =======");
System.out.println("1. Fungsi Jumlah");
System.out.println("2. Fungsi Kurang");
System.out.println("3. Fungsi Kali");
System.out.println("4. Fungsi Bagi");
System.out.println("");
int pil;
char huruf;
String hr;
char lagi;
String input;
lagi = 'y';
while (lagi == 'y')
{
System.out.print("Masukkan pilihan anda : ");
pil = masuk.nextInt();
switch (pil)
{
case 1:
{
jumlah();
}
case 2:
{
kurang();
}
case 3:
{
kali();
}
case 4:
{
bagi();
}
default:
System.out.println("Pilihan anda salah, silahkan memilih kembali");
}
System.out.println("Memilih kembali: y/t");
input = masuk.next();
lagi = input.charAt(0);
}
}
}
0 komentar:
Posting Komentar