Java典型題目 >>>>>>長期更新,java典型題目更新

來源:互聯網
上載者:User

Java典型題目 >>>>>>長期更新,java典型題目更新

1,數組順時針旋轉90度

 1   2 //數組順時針旋轉90° 3 //列變行(正 0列-->0行,1列-->1行...) 4 //行變列(反 0行-->length-1列,1行-->length-2列...) 5 public class Rotate { 6     public static void getRotate(int[][] x) { 7  8         int[][] b = new int[x[0].length][x.length]; 9         // 轉換10         for (int i = 0; i < x.length; i++) {11             for (int j = 0; j < x[i].length; j++) {12                 b[j][x.length - i - 1] = x[i][j];13             }14         }15         // 輸出16         for (int i = 0; i < b.length; i++) {17             for (int j = 0; j < b[i].length; j++) {18                 System.out.print(b[i][j] + " ");19             }20             System.out.println();21         }22 23     }24     // 測試25     public static void main(String[] args) {26         int[][] a = {{ 0, 1 ,2 }, 27                      { 0, 1 ,5 }, 28                      { 1, 1 ,6 }, 29                      { 1, 2 ,5 },30                      { 1, 2 ,5 }31                      };32         getRotate(a);33     }34 }

 運行結果:

1 1 1 0 0
2 2 1 1 1
5 5 6 5 2

 

2,九九乘法表

 1 /** 8、九九乘法表 */ 2 public class Job8 { 3  4     public static void main(String[] args) { 5         for (int i = 1; i <= 9; i++) { 6             for (int j = 1; j <= i; j++) { 7                 System.out.print(j + "*" + i + "=" + i * j + "\t"); 8             } 9             System.out.println();10         }11     }12 }

運行結果:

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.