练习题第三题还是有点错误,但我不知道错在哪

import java.util.Scanner;
import java.io.PrintStream;

public class maina {
    public static void main(String[] args) throws java.io.UnsupportedEncodingException {
        PrintStream ps = new PrintStream(System.out, true, "UTF-8");
        Scanner in = new Scanner(System.in, "UTF-8");
        int kuan;
        int gao;
       kuan =in.nextInt();
       gao =in.nextInt();
        int [][]a=new int [gao][kuan];
        int i=0;
        int j=0;
        while(i<gao) {
                while(j<kuan) {
                    a[i][j]=in.nextInt();
                    
                    j++;
                }   
                i++;
        }
        int m=0;
        int n=0;
        while(m<gao) {
                while(n<kuan) {
                    if(a[m][n]==0) {
                        ps.println(" ");
                    }
                    else if(a[m][n]==1) {
                        ps.print("*");
                        
                    }
                    n++;
                    ps.println();
                    m++;
                }
                
        }
       
         
        
    }
            }



2 条评论

  • @ 2019-05-14 14:45:13

    思考一下这几种有什么不同

    第一种:

            while(m<gao) {
                    while(n<kuan) {
                        if(a[m][n]==0) {
                            ps.println(" ");
                        }
                        else if(a[m][n]==1) {
                            ps.print("*");
                            
                        }
                        n++;
                        ps.println();
                        m++;
                    }
                    
            }
    

    第二种:

            while(m<gao) {
                    while(n<kuan) {
                        if(a[m][n]==0) {
                            ps.println(" ");
                        }
                        else if(a[m][n]==1) {
                            ps.print("*");
                         
                        n++;
                        ps.println();
                        m++;
                        }
                    }
                    
            }
    

    第三种

            while(m<gao) {
                    while(n<kuan) {
                        if(a[m][n]==0) {
                            ps.println(" ");
                        }
                        else if(a[m][n]==1) {
                            ps.print("*");
                            
                        }
                        n++;
                        ps.println();
                    }
                                  m++;
                    
            }
    

    注意:这三种都不对!!!你得自己想想怎么改才能对!!!

  • @ 2019-05-14 10:55:45

    sorry cannot type chinese somehow

  • 1