Computer Science, asked by indurkarasit, 9 months ago

Please solve the code in Java for the following by using loops:
1 2 3 4 5
5 4 3 2
2 3 4
3 4
3

Answers

Answered by Niharikamishra24
2

Answer:

Java programs to print the numbers or any different pattern is one of the easiest ways to kick off your coding skills in java. In this post I have taken some different number pattern programs in java and tried to solve them .

import java.util.Scanner;

public class MainClass

{

public static void main(String[] args)

{

Scanner sc = new Scanner(System.in);

System.out.println("How many rows you want in this pattern?");

int rows = sc.nextInt();

System.out.println("Here is your pattern....!!!");

for (int i = 1; i <= rows; i++)

{

int num = i;

for (int j = 1; j <= i; j++)

{

System.out.print(num+" ");

num = num+rows-j;

}

System.out.println();

}

sc.close();

}

}

hope it helps you.....

Answered by IIMrMartianII
42

Answer:

Heya Here's the required program mate

import java.util.Scanner;

public class MainClass

{

public static void main(String[] args)

{

Scanner sc = new Scanner(System.in);

System.out.println("How many rows you want in this pattern?");

int rows = sc.nextInt();

System.out.println("Here is your pattern....!!!");

for (int i = 1; i <= rows; i++)

{

int num = i;

for (int j = 1; j <= i; j++)

{

System.out.print(num+" ");

num = num+rows-j;

}

System.out.println();

}

sc.close();

}

}

Hope it helps dear

Similar questions