4
34
234
1234
Pattern question
Java program using for loop
Answers
Answer:
class prog
{
void main()
{
for(int i=4;i>=1;i--)
{
for(int j=i;<=4;j++)
{
System.out.print(j);}
System.out.println();
}
}
Java program to print numbered pattern
Explanation:
Java Program
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
// Create a new Scanner object
Scanner sc = new Scanner(System.in);
// Input no. of rows
System.out.println("Enter the number of rows ");
int rows = sc.nextInt();
System.out.println("---Print the pattern---");
for (int i = rows; i >= 1; i--)
{
for (int k = i; k <= rows; k++)
{
System.out.print(k + " ");
}
System.out.println();
}
}
}
Output
Enter the number of rows
4
---Print the pattern---
4
34
234
1234