Úvod do číselných vzorov v Jave

Číselné vzory sú pre čerstvých ľudí trendom, keď sa dostanú ako súčasť otázok na pohovor, pretože poskytujú dobrý brainstormingový program na analýzu kreativity a inovácie osoby. Riešenie viacerých vzorov ukazuje logické a matematické schopnosti. Je to skutočne dobrý spôsob, ako formovať rôzne vzorce pomocou všetkých týchto podmienených slučiek a syntaxí v jave, pretože pomáha zlepšovať schopnosti optimalizácie a pomáha rozvíjať logické a analytické schopnosti. Číselné vzory môžu byť nahradené akýmkoľvek znakom alebo symbolom. Ak sa naučíte vzorec čísel, môžete orámovať ktorýkoľvek zo vzorov založený na jave.

Najlepšie príklady vzorov čísel

Tu sa naučíme, ako čeliť niektorým dobrým vzorcom čísel v Jave. Pozrime sa na niektoré z dobrých vzorcov čísel v jave s príkladmi a implementáciou kódu, ktoré sú podrobne vysvetlené nižšie:

Prí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ýkon:

Prí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ýkon:

Prí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ýkon:

Prí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ýkon:

Prí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 :

Prí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ýkon:

Prí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ýkon:

Prí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ýkon:

Prí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ýkon:

Prí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ýkon:

Prí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ýkon:

Prí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ýkon:

Prí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ýkon:

Prí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ýkon:

záver

Riešenie číselných vzorov alebo akýchkoľvek vzorových vzorov zlepšuje analytickú a logickú spôsobilosť budovy. Vo väčších oblastiach poskytuje prehľad o tom, ako vytvoriť a splniť požiadavky dané pre projekt a ako efektívne ho možno s dôverou zvládnuť.

Odporúčané články

Toto je príručka pre číselné vzory v Jave. Tu diskutujeme úvod a 14 príkladov vzorcov čísel v jave spolu s implementáciou kódu. Viac informácií nájdete aj v nasledujúcich článkoch

  1. FileFhooser JavaFX
  2. Regulárne výrazy v Jave
  3. Tlačidlo JavaFX
  4. Java Booleans

Kategórie: