Kali ini kita sedikit bermain-main dengan java, yaitu membuat game penjumlahan, .
Langsung saja dicoba, . .
import java.util.Scanner;
public class GamePenjumlahan {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int a = (int) (Math.random() * 10);
int b = (int) (Math.random() * 10);
int x = 1;
System.out.print("Berapa " + a + " + " + b + " ? ");
int jawab = input.nextInt();
if (jawab == (a+b)) {
System.out.println("Benar\n");
} else {
System.out.println("Salah\n");
}
while (x < 10) {
a = (int) (Math.random() * 10);
b = (int) (Math.random() * 10);
System.out.print("Berapa " + a + " + " + b + " ? ");
jawab = input.nextInt();
if (jawab == (a+b)) {
System.out.println("Benar\n");
} else {
System.out.println("Salah\n");
}
x+=2;
}
}
}
Thank for visiting, . . Semoga bermanfaat, . .
0 Response to "Game Penjumlahan"
Post a Comment