Wprowadzenie do wzorców liczb w Javie

Wzory liczbowe są dość popularnym trendem dla osób odświeżających się w ramach pytań podczas rozmowy kwalifikacyjnej, ponieważ zapewnia dobrą burzę mózgów w celu analizy kreatywności i innowacyjności danej osoby. Rozwiązanie większej liczby wzorców wykazuje zdolności logiczne i matematyczne. Jest to rzeczywiście dobry sposób na tworzenie różnych wzorców przy użyciu wszystkich tych pętli warunkowych i składni w Javie, ponieważ pomaga improwizować umiejętności optymalizacji i pomaga rozwijać umiejętności logiczne i analityczne. Wzory liczbowe można zastąpić dowolnym znakiem lub symbolem. Jeśli nauczysz się wzoru liczbowego, możesz wykadrować dowolny wzór oparty na Javie.

Najważniejsze przykłady wzorców liczb

Tutaj nauczymy się, jak stawić czoła niektórym dobrym wzorcom liczb w Javie. Rzućmy okiem na niektóre dobre wzorce liczb w Javie z przykładami i implementacją kodu, które zostały szczegółowo wyjaśnione poniżej:

Przykład 1

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();
)
)
)

Wynik:

Przykład nr 2

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();
)
)
)
)

Wynik:

Przykład nr 3

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();
)
)
)

Wynik:

Przykład 4

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();
)
)
)

Wynik:

Przykład 5

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();
)
)
)

Wyjście :

Przykład nr 6

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();
)
)
)

Wynik:

Przykład nr 7

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();
)
)
)

Wynik:

Przykład nr 8

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();
)
)
)

Wynik:

Przykład nr 9

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();
)
)
)

Wynik:

Przykład nr 10

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();
)
)
)

Wynik:

Przykład nr 11

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();
)
)
)

Wynik:

Przykład nr 12

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();
)
)
)

Wynik:

Przykład # 13

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();
)
)
)

Wynik:

Przykład # 14

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();
)
)
)

Wynik:

Wniosek

Rozwiązywanie liczb Wzory lub dowolny wzorzec projektowy poprawia zdolności analityczne i logiczne użytkownika. W większych domenach zawiera przegląd tego, jak stworzyć i spełnić wymagania podane dla projektu oraz jak skutecznie można z nim poradzić sobie z pewnością.

Polecane artykuły

Jest to przewodnik po wzorcach liczb w Javie. Tutaj omawiamy wprowadzenie i 14 najlepszych przykładów wzorców liczb w Javie wraz z implementacją kodu. Możesz także przejrzeć następujące artykuły, aby dowiedzieć się więcej-

  1. JavaFX FileChooser
  2. Wyrażenia regularne w Javie
  3. Przycisk JavaFX
  4. Java Booleans