Rumah >Java >javaTutorial >Corak Nombor di Jawa
Corak Nombor agak menjadi trend untuk pelajar baru untuk mendapatkan sebagai sebahagian daripada soalan temu bual kerana ia menyediakan sesi sumbang saran yang baik untuk menganalisis kreativiti dan inovasi seseorang. Menyelesaikan lebih banyak corak menunjukkan keupayaan logik dan matematik. Ia sememangnya cara yang baik untuk membentuk corak yang berbeza menggunakan semua gelung dan sintaks bersyarat ini dalam java. Ia membantu dalam menambah baik kemahiran pengoptimuman dan membantu membangunkan kebolehan logik dan analitikal. Ia boleh digantikan dengan mana-mana watak atau simbol. Jika anda mempelajari corak nombor, anda boleh membingkai mana-mana corak berdasarkan java.
IKLAN Kursus Popular dalam kategori ini JAVA MASTERY - Pengkhususan | 78 Siri Kursus | 15 Ujian Olok-olokDi sini kita akan belajar cara menghadapi beberapa Corak Nombor yang baik. Mari kita lihat beberapa Corak Nombor yang baik dalam java dengan contoh dan pelaksanaan kod, yang diterangkan di bawah secara terperinci:
Kod:
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(); } } }
Output:
Kod:
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(); } } } }
Output:
Kod:
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(); } } }
Output:
Kod:
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(); } } }
Output:
Kod:
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(); } } }
Output:
Kod:
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(); } } }
Output:
Kod:
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(); } } }
Output:
Kod:
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(); } } }
Output:
Kod:
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(); } } }
Output:
Kod:
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(); } } }
Output:
Kod:
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(); } } }
Output:
Kod:
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(); } } }
Output:
Kod:
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(); } } }
Output:
Kod:
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(); } } }
Output:
Menyelesaikan Corak nombor atau sebarang corak reka bentuk meningkatkan kebolehan membina analitik dan logik seseorang. Dalam domain yang lebih besar, ia memberikan gambaran keseluruhan tentang cara membuat dan memenuhi keperluan yang diberikan untuk projek dan sejauh mana ia boleh ditangani dengan penuh keyakinan.
Atas ialah kandungan terperinci Corak Nombor di Jawa. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!