>  기사  >  Java  >  Java의 숫자 패턴

Java의 숫자 패턴

王林
王林원래의
2024-08-30 16:25:12923검색

숫자 패턴은 개인의 창의성과 혁신을 분석하기 위한 좋은 브레인스토밍 세션을 제공하기 때문에 신입생들이 인터뷰 질문의 일부로 받는 경향이 있습니다. 더 많은 패턴을 해결하면 논리적, 수학적 능력이 나타납니다. 이는 실제로 Java에서 이러한 모든 조건부 루프와 구문을 사용하여 다양한 패턴을 형성하는 좋은 방법입니다. 최적화 기술을 향상시키는 데 도움이 되며 논리적, 분석적 적성을 개발하는 데 도움이 됩니다. 임의의 문자나 기호로 대체될 수 있습니다. 숫자 패턴을 배우면 자바를 기반으로 어떤 패턴이든 프레임화할 수 있습니다.

광고 이 카테고리에서 인기 있는 강좌 JAVA MASTERY - 전문 분야 | 78 코스 시리즈 | 15가지 모의고사

숫자 패턴의 대표적인 예

여기서 우리는 좋은 숫자 패턴에 직면하는 방법을 배울 것입니다. 아래에 자세히 설명된 예제와 코드 구현을 통해 Java의 좋은 숫자 패턴 중 일부를 살펴보겠습니다.

예시 #1

코드:

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

출력:

Java의 숫자 패턴

예시 #2

코드:

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

출력:

Java의 숫자 패턴

예시 #3

코드:

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

출력:

Java의 숫자 패턴

예시 #4

코드:

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

출력:

Java의 숫자 패턴

예시 #5

코드:

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

출력:

Java의 숫자 패턴

예시 #6

코드:

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

출력:

Java의 숫자 패턴

예 #7

코드:

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

출력:

Java의 숫자 패턴

예시 #8

코드:

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

출력:

Java의 숫자 패턴

예시 #9

코드:

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

출력:

Java의 숫자 패턴

예시 #10

코드:

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

출력:

Java의 숫자 패턴

예시 #11

코드:

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

출력:

Java의 숫자 패턴

예시 #12

코드:

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

출력:

Java의 숫자 패턴

예시 #13

코드:

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

출력:

Java의 숫자 패턴

예시 #14

코드:

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

출력:

Java의 숫자 패턴

결론

숫자 패턴이나 디자인 패턴을 해결하면 분석적이고 논리적인 건축 적성이 향상됩니다. 더 큰 영역에서는 프로젝트에 주어진 요구 사항을 생성하고 충족하는 방법과 자신감을 가지고 얼마나 효과적으로 처리할 수 있는지에 대한 개요를 제공합니다.

위 내용은 Java의 숫자 패턴의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
이전 기사:Java의 별 패턴다음 기사:Java의 별 패턴