Question:
Print the following pattern for the given N number of rows.
Pattern for N = 4
Ans: package HelloWorld;
import java.util.Scanner;
public class LearningJava {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
// Print the following pattern for the given N number of rows.
// Pattern for N = 4
// 1
// 21
// 321
// 4321
int n = scan.nextInt();
for(int i=1;i<=n;i++){
for(int j=i;j>=1;j--){
System.out.print(j);
}
System.out.println();
}
}
}
- yaha hamne j column ko i se start kiya hai, taaki i se start ho sake; j ko grater than rkha hai j ko se bdha rkha hai aur 1 tk ja rha hai , aur j-- decrement kiya hai .
Comments
Post a Comment