Úvod do číselných vzorů v Javě

Číselné vzory jsou pro nováčky trendem, který se dostávají jako součást otázek na pohovor, protože poskytuje dobrý brainstorming, který analyzuje kreativitu a inovaci člověka. Řešení více vzorů ukazuje logické a matematické schopnosti. Je to opravdu dobrý způsob, jak formovat různé vzorce pomocí všech těchto podmíněných smyček a syntaxí v javě, protože pomáhá zlepšovat dovednosti optimalizace a pomáhá rozvíjet logické a analytické schopnosti. Číselné vzory lze nahradit libovolným znakem nebo symbolem. Pokud se naučíte vzorec čísel, můžete orámovat kterýkoli ze vzorů na základě javy.

Nejlepší příklady číselných vzorů

Zde se naučíme, jak čelit některým z dobrých vzorců čísel v Javě. Pojďme se podívat na některé z dobrých vzorců čísel v javě s příklady a implementací kódu, které jsou podrobně vysvětleny níže:

Příklad č. 1

Kód:

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

Výstup:

Příklad č. 2

Kód:

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

Výstup:

Příklad č. 3

Kód:

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

Výstup:

Příklad č. 4

Kód:

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

Výstup:

Příklad č. 5

Kód:

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

Výstup :

Příklad č. 6

Kód:

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

Výstup:

Příklad č. 7

Kód:

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

Výstup:

Příklad č. 8

Kód:

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

Výstup:

Příklad č. 9

Kód:

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

Výstup:

Příklad č. 10

Kód:

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

Výstup:

Příklad č. 11

Kód:

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

Výstup:

Příklad č. 12

Kód:

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

Výstup:

Příklad č. 13

Kód:

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

Výstup:

Příklad č. 14

Kód:

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

Výstup:

Závěr

Řešení číselných vzorů nebo jakéhokoli vzorového vzoru zlepšuje analytickou a logickou schopnost budovy. Ve větších oblastech poskytuje přehled o tom, jak vytvářet a plnit požadavky dané pro projekt a jak efektivně je možné s důvěrou řešit.

Doporučené články

Toto je průvodce číslovými vzory v Javě. Zde diskutujeme úvod a 14 nejlepších příkladů vzorců čísel v javě spolu s implementací kódu. Další informace naleznete také v následujících článcích

  1. JavaFX FileChooser
  2. Regulární výrazy v Javě
  3. Tlačítko JavaFX
  4. Java Booleans

Kategorie: