Answer:
Hi There was small mistake. It is working fine for me. When you run from command line - use LoopPattern, not looppatern
import java.util.Scanner;
public class Looppattern {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter how man levels you need: ");
int levels = sc.nextInt();
System.out.println("\n---------------Pattern A-----------------\n");
for (int p = 1; p <= levels; p++) {
for (int k = 1; k <= p; k++) { // increasing each level printing
System.out.print(k);
}
System.out.println();
}
System.out.println("\n---------------Pattern B-----------------\n");
int r = levels;
for (int p = 1; p <= levels; p++) {
for (int k = 1; k <= r; k++) {
System.out.print(k);
}
r--; // decreasing levels
System.out.println();
}
System.out.println("\n---------------Pattern C-----------------\n");
for (int p = 1; p <= levels; p++) { // here incresing
for (int k = p; k > 0; k--) { // and here decreasing pattern to
// achieve our required pattern
System.out.print(k);
}
System.out.println();
}
System.out.println("\n---------------Pattern D-----------------\n");
r = levels;
for (int p = 1; p <= levels; p++) {
for (int k = 1; k <= r; k++) {
System.out.print(k);
}
r--; // decreasing levels
System.out.println();
}
}
}
Explanation: