Penambahan Acak

Asslamualaikum, ..
Semoga hari ini kita masih di beri kesehatan rohani jasmani, tentunya agar tetap bisa ngoding, . . hhe
Kali ini saya akan membagikan tentang Penambahan acak pada pemrograman jaa, .
selamat mencoba, .

import java.util.Scanner;

public class RandomAddition {

public static void main(String[] iriahus) {
@SuppressWarnings("resource")
Scanner s = new Scanner(System.in);

final int NUMBER_OF_QUESTION = 3;
int count = 0;
int correct = 0;
String output = "";
long start = System.currentTimeMillis() / 1000;

do {
int a = (int)(1 + System.currentTimeMillis() / 2 % 15);
int b = (int)(1 + System.currentTimeMillis() / 3 % 15);

System.out.print("What is " + a + " + " + b + "? ");
int ans = s.nextInt();
count++;

if (ans == a + b) {
System.out.println("Great job!\n");
correct++;
} else {
System.out.println("Wrong! " + a + " + " + b +
" should be " + (a + b) + "\n");
}

output += "\n" + a + " + " + b + " = " + ans +
" " + ((a + b == ans) ? " Correct" : " Wrong");
} while (count < NUMBER_OF_QUESTION);

long end = System.currentTimeMillis() / 1000;
long testTime = end - start;

System.out.println(output);
System.out.println("\nYou are " + correct + " correct out of " + count);
System.out.println("Testing time " + testTime + " seconds");

}

}

Semoga bermanfaat,  . .

Subscribe to receive free email updates:

0 Response to "Penambahan Acak"

Post a Comment