Heim >Java >javaLernprogramm >Zahlenmuster in Java
Number Patterns are quite a trend for freshers to get as part of interview questions as it provides a good brainstorming session to analyze a person’s creativity and innovation. Solving more of patterns show logical and mathematical capability. It is indeed a good way to form different patterns using all these conditional loops and syntaxes in java. It helps in improvising the skills of optimization and helps develop logical and analytical aptitude. It can be substituted with any character or symbol. If you learn number pattern, you can frame any of the patterns based on java.
ADVERTISEMENT Popular Course in this category JAVA MASTERY - Specialization | 78 Course Series | 15 Mock TestsHere we will learn how to face some of the good Number Patterns. Let’s have a peek at some of the good Number Patterns in java with examples and code implementation, which are explained below in detail:
Code:
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:
Code:
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:
Code:
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:
Code:
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:
Code:
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:
Code:
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:
Code:
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:
Code:
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:
Code:
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:
Code:
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:
Code:
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:
Code:
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:
Code:
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:
Code:
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:
Solving number Patterns or any design pattern improves a person’s analytical and logical building aptitude. In bigger domains, it provides an overview of how to create and fulfil requirements given for a project and how effectively it can be tackled with confidence.
Das obige ist der detaillierte Inhalt vonZahlenmuster in Java. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!