您的位置:首页 > 编程语言 > Java开发

Java自学新手,刚看完数组自写转置数组程序,大佬们给几分?

2018-01-21 20:44 225 查看
打个分吧!!

代码::

public class Practice1 {

  public void ShowArray(int a[][]) {
   
 for(int x[]:a) {
   
  for(int y:x) {
     
    
System.out.print(y+" ");
  

  }System.out.println();
 
  }System.out.println();
    }

  public void Transpose(int a[][]) {                       
   int b[][]=new int[a[0].length][a.length];
   for(int i=0;i<a.length;i++) {
 
  for(int j=0;j<a[i].length;j++) {
   
b[j][i]=a[i][j];
   
}
 
 }ShowArray(b);
  }

   public static void main(String[] args) {
 
  Practice1 ShowArrayer=new Practice1();
 
  Practice1 Transposeer=new Practice1();
 
  int arr[][]= {{1,2,3,4},{5,6,7,8}};
 
  ShowArrayer.ShowArray(arr);
 
  Transposeer.Transpose(arr);

          }

 }

运行结果::

1 2 3 4 

5 6 7 8 

1 5 

2 6 

3 7 

4 8 

大佬们请批评指教。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: