Advertisement
cd62131

Excise2801

Feb 7th, 2014
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.06 KB | None | 0 0
  1. import java.util.Random;
  2. import java.util.Scanner;
  3.  
  4. public class Excise2801 {
  5.   public static void main(String[] args) {
  6.     Scanner in = new Scanner(System.in);
  7.     Random r = new Random();
  8.     System.out.print("x: ");
  9.     int x = in.nextInt();
  10.     System.out.print("y: ");
  11.     int y = in.nextInt();
  12.     System.out.print("n: ");
  13.     int n = in.nextInt();
  14.     String[][] xy = new String[x][y];
  15.     for (int i = 0; i < x; i++)
  16.       for (int j = 0; j < y; j++)
  17.         xy[i][j] = "-";
  18.     for (; n > 0; n--)
  19.       xy[r.nextInt(x)][r.nextInt(y)] = "*";
  20.     for (int i = 0; i < x; i++) {
  21.       for (int j = 0; j < y; j++)
  22.         System.out.print(xy[i][j]);
  23.       System.out.println();
  24.     }
  25.     int point = 0;
  26.     while (true) {
  27.       System.out.print("X: ");
  28.       int X = in.nextInt();
  29.       if (X < 0 || X >= x) continue;
  30.       System.out.print("Y: ");
  31.       int Y = in.nextInt();
  32.       if (Y < 0 || Y >= y) continue;
  33.       if (xy[X][Y] == "*") break;
  34.       point += 10;
  35.     }
  36.     in.close();
  37.     System.out.println("Score: " + point);
  38.   }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement