This is a menu driven program. The user inputs a string and can select either of 2 patterns to be printed using the given string. These are the 2 patterns:
This is the code for my program:
import java.util.Scanner;
class MenuDrivenPattern
{
public static void main()
{
System.out.println("\f");
Scanner sc = new Scanner(System.in);
while (true)
{
System.out.println("\nMENU DRIVEN PROGRAM");
System.out.println("\nMake your choice");
System.out.println("\n");
System.out.println("\nPattern 1");
System.out.println("\nPattern 2");
System.out.println("\nExit");
int choice = sc.nextInt();
System.out.println("Enter a word");
String s = sc.next();
s = s.toUpperCase();
switch (choice)
{
case 1:
for (int a = s.length(); a >= 1; a--)
{
for (int b = 0; b < a; b++)
{
char x = s.charAt(b);
System.out.print(x);
}
System.out.println();
}
case 2:
for(int c = 0; c < s.length(); c++)
{
for (int d = c; d < s.length(); d++)
{
char y = s.charAt(d);
System.out.print(y);
}
System.out.println();
}
case 3:
System.out.println("Thank you for using this program");
System.exit(0);
default:
System.out.println("Please enter a singular, valid word. Thank you.");
}
}
}
}
There is the error it is showing:
Error:
Could not find or load main class Main
Caused by: java.lang.ClassNotFoundException: Main
I am relatively new to Java and do not understand this error. What changes do I make to the program to make it compile properly?