首页  >  文章  >  Java  >  Java 中的数字模式

Java 中的数字模式

王林
王林原创
2024-08-30 16:25:12921浏览

数字模式对于应届生来说是一种相当流行的面试问题,因为它提供了一个很好的头脑风暴会议来分析一个人的创造力和创新能力。解决更多的模式显示出逻辑和数学能力。这确实是使用 java 中的所有这些条件循环和语法来形成不同模式的好方法。它有助于即兴发挥优化技能,并有助于培养逻辑和分析能力。它可以用任何字符或符号替换。如果你学习了数字模式,你可以基于java构建任何数字模式。

广告 该类别中的热门课程 JAVA 掌握 - 专业化 | 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