數位模式對應屆生來說是相當流行的面試問題,因為它提供了一個很好的腦力激盪會議來分析一個人的創造力和創新能力。解決更多的模式顯示出邏輯和數學能力。這確實是使用 java 中所有這些條件循環和語法來形成不同模式的好方法。它有助於即興發揮優化技能,並有助於培養邏輯和分析能力。它可以用任何字元或符號替換。如果你學習了數位模式,你可以基於java建立任何數位模式。
廣告 該類別中的熱門課程 JAVA 掌握 - 專業化 | 78 課程系列 | 15 次模擬測驗在這裡我們將學習如何面對一些好的數字模式。讓我們透過範例和程式碼實作來看看java中一些好的數字模式,下面詳細解釋:
代碼:
import java.util.Scanner; public class Pattern1 { public static void main (String [] args) { Scanner scanner = new Scanner(System.in); System.out.println("Enter the number of rows "); int rows = scanner.nextInt(); System.out.println("Printing Pattern"); for (int i = 1; i <= rows; i++) { for (int j = 1; j <= i; j++) { System.out.print(j + " "); } System.out.println(); } } }
輸出:
代碼:
import java.util.Scanner; public class Pattern2 { public static void main (String [] args) { { Scanner scanner = new Scanner(System.in); System.out.println("Enter the number of rows"); int rows = scanner.nextInt(); System.out.println("Printing Pattern"); for (int i = 1; i <= rows; i++) { for (int j = 1; j <= i; j++) { System.out.print(i + " "); } System.out.println(); } } } }
輸出:
代碼:
import java.util.Scanner; public class Pattern_3 { public static void main (String [] args) { Scanner scanner = new Scanner(System.in); System.out.println("Enter the number of rows"); int rows = scanner.nextInt(); System.out.println("Printing Pattern"); for (int i = 1; i <= rows; i++) { for (int j = 1; j <= i; j++) { System.out.print(j + " "); } System.out.println(); } for (int i = rows; i >= 1; i--) { for (int j = 1; j < i; j++) { System.out.print(j + " "); } System.out.println(); } } }
輸出:
代碼:
import java.util.Scanner; public class Pattern4 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("Enter the number of rows"); int rows = scanner.nextInt(); System.out.println("Printing Pattern"); for (int i = rows; i >= 1; i--) { for (int j = 1; j <= i; j++) { System.out.print(j + " "); } System.out.println(); } for (int i = 1; i <= rows; i++) { for (int j = 1; j <= i; j++) { System.out.print(j + " "); } System.out.println(); } } }
輸出:
代碼:
import java.util.Scanner; public class Pattern5 { public static void main(String [] args) { Scanner scanner = new Scanner(System.in); System.out.println("Enter the number of rows"); int rows = scanner.nextInt(); System.out.println("Printing Pattern"); for (int i = rows; i >= 1; i--) { for (int j = i; j >= 1; j--) { System.out.print(j + " "); } System.out.println(); } for (int i = 1; i <= rows; i++) { for (int j = i; j >= 1; j--) { System.out.print(j + " "); } System.out.println(); } } }
輸出:
代碼:
import java.util.Scanner; public class Pattern6 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("Enter the number of rows "); int rows = scanner. nextInt(); System.out.println("Printing Pattern"); for (int i = 1; i <= rows; i++) { for (int j = rows; j > i; j--) { System.out.print(" "); } for (int k = 1; k <= i; k++) { System.out.print(k + " "); } System.out.println(); } } }
輸出:
代碼:
import java.util.Scanner; public class Pattern7 { public static void main (String [] args) { Scanner scanner = new Scanner (System.in); System.out.println("Enter the number of rows "); int rows = scanner.nextInt(); System.out.println("Printing Pattern"); for (int i = 1; i <= rows; i++) { for (int j = rows; j >= i; j--) { System.out.print(j + " "); } System.out.println(); } } }
輸出:
代碼:
import java.util.Scanner; public class Pattern8 { public static void main (String[] args) { Scanner scanner = new Scanner (System.in); System.out.println("Enter the number of rows"); int rows = scanner.nextInt(); System.out.println("Printing Pattern"); for (int i = rows; i >= 1; i--) { for (int j = rows; j >= i; j--) { System.out.print(j + " "); } System.out.println(); } } }
輸出:
代碼:
import java.util.Scanner; public class Pattern9 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("Enter the number of rows"); int rows = scanner.nextInt(); System.out.println("Printing Pattern "); for (int i = rows; i >= 1; i--) { for (int j = 1; j <= i; j++) { System.out.print(j + " "); } System.out.println(); } } }
輸出:
代碼:
import java.util.Scanner; public class Pattern10 { public static void main(String [] args) { Scanner scanner = new Scanner(System.in); System.out.println("Enter the number of rows"); int rows = scanner.nextInt(); int k = 1; System.out.println("Printing Pattern"); for (int i = 1; i <= rows; i++) { for (int j = 1; j <= i; j++) { System.out.print(k + " "); k++; } System.out.println(); } } }
輸出:
代碼:
import java.util.Scanner; public class Pattern11 { public static void main(String[] args) { Scanner scanner = new Scanner (System.in); System.out.println("Enter number of rows"); int rows = scanner.nextInt(); System.out.println("Printing Pattern"); for (int i = 1; i <= rows; i++) { for (int j = i; j >= 1; j--) { System.out.print(j + " "); } System.out.println(); } } }
輸出:
代碼:
import java.util.Scanner; public class Pattern12 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("Enter the number of rows"); int rows = scanner.nextInt(); System.out.println("Pattern Printing"); for (int i = 1; i <= rows; i++) { int temp = i; for (int j = i; j >= 1; j--) { System.out.print(temp + " "); temp = temp + rows; } System.out.println(); } } }
輸出:
代碼:
import java.util.Scanner; public class Pattern13 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("Enter the number of rows"); int rows = scanner.nextInt(); System.out.println("Pattern Printing"); for (int i = 1; i <= rows; i++) { for (int j = rows; j > i; j--) { System.out.print(" "); } int temp= 1; for (int k = 1; k <= i; k++) { System.out.print(temp + " "); temp = temp * (i - k) / (k); } System.out.println(); } } }
輸出:
代碼:
import java.util.Scanner; public class Pattern14 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("Enter number of rows"); int rows = scanner.nextInt(); System.out.println("Pattern Printing"); for (int i = 1; i <= rows; i++) { for (int j = 1; j <= i; j++) { System.out.print(j + " "); } for (int k = i - 1; k >= 1; k--) { System.out.print(k + " "); } System.out.println(); } } }
輸出:
解決數位模式或任何設計模式可以提高一個人的分析和邏輯建構能力。在更大的領域中,它概述瞭如何創建和滿足專案的要求,以及如何有效地自信地解決它。
以上是Java 中的數字模式的詳細內容。更多資訊請關注PHP中文網其他相關文章!