如何从方法返回并打印2D数组?

时间:2018-11-08 01:56:55

标签: java arrays methods

我正在尝试打印表格,代码在这里:

int [][] Ratingarray = new int [hotel][years];
for (int row = 0; row < Ratingarray.length; row++){
    System.out.print("Hotel " + (row) + ":" + " ");
    for (int column = 0; column < Ratingarray[row].length; column++){
        Ratingarray[row][column] = (int) (Math.random() * 5 + 1);
        String rating;
        switch (Ratingarray[row][column]){
           case 1:
               rating = "*";
               break;
           case 2:
               rating = "**";
               break;
           case 3:
               rating = "***";
               break;
           case 4:
               rating = "****";
           default:
              rating = "*****";
         }
         if(rating == "*" || rating == "**"){
            System.out.print("\t" + rating + "\t\t\t\t");
         }else{
            System.out.print("\t" + rating + "\t\t\t");
         }
      }
      System.out.println();
   }    
   return; \\not sure what to return
}

此方法从先前的方法获取数组值。 当我在main方法中调用此方法时,它返回[[I @ 614c5515 我想这种方法将数组值打印为星号 我不知道该返回什么主要方法。我的方法以if else语句结束,以打印正确数量的星号,因此我不确定如何使用return语句。

0 个答案:

没有答案