Write a program in java forming a pattern:
12345
2345
345
45
5
Answers
Answered by
34
/* Java Program to print the number pattern */
import java.util.Scanner;
public class NumPattern
{
public static void printNumPattern(int n)
{
int i, j;
for(i=1; i<=n; i++)
{
for(j=i; j<=n; j++)
{
System.out.print(j);
}
System.out.println();
}
}
// Driver Function
public static void main(String args[])
{
Scanner scanner = new Scanner(System.in);
System.out.print("Enter n: ");
int n = scanner.nextInt();
printNumPattern(n);
}
}
// Driver Function
public static void main(String args[])
{
int n = 5;
printNumPattern(n);
}
Attachments:
muakanshakya:
perfect ans ! :)
Similar questions