Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class e15 {
  3. public static void main(String [] args) {
  4. Scanner input = new Scanner(System.in);
  5. // pelikentän koko
  6. System.out.println("Give the table size: ");
  7. int size = input.nextInt();
  8. String[] table = new String[size];
  9. int bombs = size / 3;
  10. boolean lost = false;
  11.  
  12. // kentän tulostus
  13. for (int i=0; i<size; i++) {
  14. table[i] = "[ ]";
  15. System.out.print(table[i]);
  16. }
  17. // pommien paikat
  18. while (bombs>0) {
  19. int i = MyMath.getRandom(0, size-1);
  20. if (!table[i].equals("[B]")) {
  21. table[i] = "[B]";
  22. bombs--;
  23. }
  24. }
  25. // paikan syöte
  26. System.out.println("\nChoose your spot >:)");
  27. int spot = input.nextInt()-1;
  28.  
  29. for (int i=0; i<size; i++) {
  30. if (i==spot) {
  31. System.out.print("[P]");
  32. } else {
  33. System.out.print("[ ]");
  34. }
  35. }
  36. }
  37. }
  38. class MyMath {
  39. public static int getRandom(int min, int max) {
  40. return (int) (Math.random()*((max-min)+1))+min;
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement