Scanner in = new Scanner(System.in); System.out.println("please assign value to n:"); int n = in.nextInt(); Scanner im = new Scanner(System.in); System.out.println("please assign value to m"); int m = im.nextInt(); //set a 2D array String[][]symmeTrical =new String[n][m]; int x = n * m / 4; for (int i = 0; i < x; i++) { int j = (int)(Math.random()*((n-1))); int u = (int)(Math.random()*((m-1))); System.out.println("随机的点为:("+j+","+u+")"); symmeTrical[j][u] = "*"; symmeTrical[j][m-u-1] = "*"; } for (int row = 0; row < symmeTrical.length; row++) { for (int col = 0; col < symmeTrical[0].length; col++) { if (symmeTrical[row][col] == null){ symmeTrical[row][col] = " "; } System.out.print( symmeTrical[row][col]+" "); } System.out.println(); }
Java 生成n*m的二维数组,随机生成n*m/4个点,再生成每个点的对称点,最后输出
最新推荐文章于 2023-03-21 17:34:26 发布