Commit 1c054cab by Patryk Czarnik

Zadanie WynikMnozenia

parent 7147a6c0
package p05_petle;
import java.util.Random;
import java.util.Scanner;
public class WynikMnozenia_v1 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Random random = new Random();
int x = random.nextInt(20) + 1;
int y = random.nextInt(20) + 1;
int wynik = x*y;
System.out.println("Ile to jest " + x + " razy " + y + " ? ");
int odp = scanner.nextInt();
int proba = 1;
while(odp != wynik) {
System.out.println("Błędna odpowiedź, spróbuj jeszcze raz:");
odp = scanner.nextInt();
proba++;
}
System.out.println("Poprawna odpowiedź. Udało się w próbie nr " + proba);
}
}
package p05_petle;
import java.util.Random;
import java.util.Scanner;
public class WynikMnozenia_v2 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Random random = new Random();
int x = random.nextInt(20) + 1;
int y = random.nextInt(20) + 1;
int wynik = x*y;
int proba = 0;
int odp;
do {
System.out.println("Ile to jest " + x + " razy " + y + " ? ");
odp = scanner.nextInt();
proba++;
} while(odp != wynik);
System.out.println("Poprawna odpowiedź. Udało się w próbie nr " + proba);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment