不错。
- import java.io.*;
- class HeimaDemo{
- public static void main (String []args) throws IOException{
- BufferedReader br = new BufferedReader(
- new InputStreamReader(System.in) );
- int x = 0 ;
- System.out.println("请输入一个大于2的数字,初始化图形");
- while(true){
- String line = br.readLine();
- x = Integer.parseInt(line);
- if(x>2){
- break;
- }
- System.out.println("请输入一个大于2的数字!");
- }
- char [][]arr = ready(x);
- print(arr);
- int y = 0 ;
- System.out.println("请输入一个大于0的数字,图形将会翻转。输入exit退出。");
- while(true){
- String line = br.readLine();
- boolean b=line.matches("[0-9]*");
- if(b) {
- y=Integer.parseInt(line);
- for(y=y%4;y>0 ;y--){
- arr = spin(arr);
- }
- print(arr);
-
- System.out.println("请输入一个大于0的数字!输入exit退出");
- }
- else{
- if(line.equals("exit")){
- break;
- }
- else
- System.out.println("输入的数字有误!");
- }
- }
- }
-
- public static char[][] ready(int x){
- char [][]arr = new char[x][x];
- for( int n = 0;n < x ; n++ ){
- for( int m = 0;m < x ; m++ ){
- if(n+m>=(x-1)/2 && n+m<= x/2+x-1 && m-n<=x/2 && n-m<=x/2 ){
- arr[n][m] = '*';
- }
- }
- }
- arr[0][(x-1)/2-1] = 'O';
- arr[0][x/2+1] = 'O';
- return arr;
- }
-
- public static void print(char[][] arr){
- int x =arr.length;
- for( int n = 0;n < x ; n++ ){
- for( int m = 0;m < x ; m++ ){
- System.out.print(arr[n][m]);
- }
- System.out.println();
- }
- }
-
- public static char[][] spin(char[][] arr){
- int x =arr.length;
-
- char[][] temp = new char[x][x];
- for( int n = 0;n < x ; n++ ){
- for( int m = 0;m < x ; m++ ){
- temp[m][x-n-1] = arr[n][m] ;
- }
- }
- return temp ;
- }
- }
复制代码 |