How to print numbers 1 to 10 in peramid by using Java language
1 2 3 4
5 6 7
8 9
10
Answers
Answered by
1
Answer:
public class Tpattern
{
public static void main(String[] args)
{
int i=0,j=0,n=4,k=1;
for(i=1; i<n+1; i++)
{
for(j=0; j<i; j++)
System.out.print(" "+k++);
System.out.println(" ");
}
}
}
Answered by
1
Java Program :
Explanation:
public class Series//class definition.
{
public static void main(String[] args) //Main function
{
int series=1;//variable declaration.
for(int i=4;i>=1;i--)//first for loop.
{
for(int j=1;j<=i;j++)//second for loop.
{
System.out.print(series+" ");//print thr value.
series++;
}
System.out.println(" ");//for line change.
}
}
}
Output:
- The above program print the above defined series.
Code Explanation:
- The above code is written in java language, in which there is a two for loop.
- The first for loop is used for the length and the second for loop is used for size.
Learn More:
- Java : https://brainly.in/question/13792074
Similar questions