Please solve the following JAVA code using loops:
1 2 3 4 5
5 4 3 2
3 4 5
4 3
3
Answers
Answered by
3
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 . Please add more pattern and their code in the comment sections.
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
35
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
Answered by
39
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
Accountancy,
5 months ago
Biology,
10 months ago
Math,
10 months ago
Math,
1 year ago
Math,
1 year ago