Write a JAVA program for the following pattern correctly-
1
2 5
3 6 8
4 7 9 10
Answers
Answered by
4
Answer:
import java.util.*;
public class Test
{
public static void Pattern()
{
int i,j;
int k;
int n=4;
for(i=1; i<=n; i++)
{
k=i;
for(j=1; j<=i; j++)
{
System.out.print(k+" ");
k=k+n-j;
}
System.out.println();
}
}
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
Test t=new Test();
t.Pattern();
}
}
Answered by
8
Explanation:
import java.util.*;
public class Test
{
public static void Pattern()
{
int i,j;
int k;
int n=4;
for(i=1; i<=n; i++)
{
k=i;
for(j=1; j<=i; j++)
{
System.out.print(k+" ");
k=k+n-j;
}
System.out.println();
}
}
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
Test t=new Test();
t.Pattern();
}
}
hope it helps
Similar questions