Introduktion till antal mönster i Java

Antalet mönster är en ganska trend för freshers att få som en del av intervjufrågor eftersom det ger en bra brainstorming session för att analysera en persons kreativitet och innovation. Att lösa mer av mönster visar logisk och matematisk förmåga. Det är verkligen ett bra sätt att bilda olika mönster med alla dessa villkorade slingor och syntaxer i java eftersom det hjälper till att improvisera optimeringsförmågan och hjälper till att utveckla den logiska och analytiska lämpligheten. Antalmönster kan ersättas med valfritt tecken eller symbol. Om du lär dig talmönster kan du rama in något av mönstren baserade på java.

Toppexempel på antal mönster

Här kommer vi att lära dig hur man möter några av de goda antalet mönster i Java. Låt oss ta en titt på några av de goda antalet mönster i java med exempel och kodimplementering som förklaras nedan i detalj:

Exempel 1

Koda:

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

Produktion:

Exempel 2

Koda:

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

Produktion:

Exempel 3

Koda:

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

Produktion:

Exempel 4

Koda:

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

Produktion:

Exempel 5

Koda:

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

Utgång :

Exempel 6

Koda:

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

Produktion:

Exempel 7

Koda:

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

Produktion:

Exempel 8

Koda:

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

Produktion:

Exempel 9

Koda:

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

Produktion:

Exempel 10

Koda:

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

Produktion:

Exempel 11

Koda:

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

Produktion:

Exempel 12

Koda:

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

Produktion:

Exempel 13

Koda:

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

Produktion:

Exempel 14

Koda:

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

Produktion:

Slutsats

Att lösa antal mönster eller vilket designmönster som helst förbättrar personens analytiska och logiska byggnadsegenskaper. På större domäner ger det en översikt över hur man skapar och uppfyller de krav som ställs för ett projekt och hur effektivt det kan hanteras med förtroende.

Rekommenderade artiklar

Detta är en guide till nummermönster i Java. Här diskuterar vi introduktionen och topp 14 exempel på talmönster i java tillsammans med dess kodimplementering. Du kan också titta på följande artiklar för att lära dig mer-

  1. JavaFX FileChooser
  2. Regelbundna uttryck i Java
  3. JavaFX-knapp
  4. Java Booleans

Kategori: