Computer Science, asked by siddhi265269, 1 year ago

HOW TO PRINT THE FOLLOWING PATTERN IN JAVA
5
4 5
3 4 5
2 3 4 5
1 2 3 4 5

Answers

Answered by Anonymous
92

In Java Programming how to print the pattern of 13 numbers , the steps are given as follows :

import java.util.*;

class np13

{

public static void main(String args[])

{

int i,j,n;

Scanner sc = new Scanner(System.in);

System.out.println("Enter the no of lines");

n=sc.nextInt();

for(i=n;i>=1;i--)

{

for(j=n;j>=i;j++)

{

System.out.print(j);

}

System.out.println("");

}

}

}

Note :

The above steps are in separate lines only. Because of LaTeX problem they may appear colliding. I am sorry for that.


divyansh101dabral: i am not doing unnecessary chat
divyansh101dabral: i just want clarification on the answer
divyansh101dabral: i wrote it on IDE and it goes on forever
divyansh101dabral: since j is increasing the condition j>=i never becomes false
divyansh101dabral: resulting in infinite loop
divyansh101dabral: pls read my chat
divyansh101dabral: this infinite for loop with j never stops
divyansh101dabral: koi mera logic samjha
divyansh101dabral: kisi ko samajh aaya ki ye galat kyon hai, kisi main dimag hai itna
Answered by siddhartharao77
88

Sample Program to Print the pattern:

class Brainly

{

public static void main(String args[])

{

for(int i = 5; i >= 1; i--)

{

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

{

System.out.print(j);

}

System.out.println(" ");

}

}

}

Output:

5

4 5

3 4 5

2 3 4 5

1 2 3 4 5

Hope it helps!


shardul1925: as usual..a other amazing answer sir..
siddhartharao77: Thanks everyone
divyansh101dabral: yeh galat lag raha hai
divyansh101dabral: accha ni sahi hai
divyansh101dabral: maine j=i ko j=1 samajh liya
siddhi265269: thanks for the answer
siddhartharao77: Welcome!
Anonymous: super annaya❤️❤️
siddhartharao77: Thanks chelli!
Similar questions