Home > Back-end > Java small white help, Java based questions, ask everybody to help
Java small white help, Java based questions, ask everybody to help
Time:09-24
Topic example: (is not a problem)
Welcome interested in program bosses in the post below message, will not be regularly and pored over Java topics for bosses to challenge
CodePudding user response:
Readily write in a
Public class Test3 { Public static int [] [] createArray (int row) { If (row<=0) return null; Int res [] []=new int [row] []; for (int i=0; iRes [I]=new int [row - I]; /* for (int j=0; jRes [I] [j]=0; } */ } return res; }
Public static void printArray (int [] [] a) { If (a==null) { System. The out. Println (" a is null. "); } for (int i=0; ifor (int j=0; jSystem. The out. Printf (" % d ", a [I] [j]); } System.out.println(); } }
Public static void main (String [] args) { Scanner sc=new Scanner(System.in); Int row=0; While (true) { Try { System. The out. Printf (" please enter the number of lines: "); The row=sc. NextInt (); If (row<=0) throw new Exception (" error "); break; } the catch (Throwable e) { System. The out. Println (" input error, please heavy lose, "); } } Int [] [] a=createArray (row); PrintArray (a); } }