If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Enjoy an ad free experience by logging in. Not a member yet? Register.

Error: Could not find or load main class Program

New to programming, this is an assignment I am working on. I have hit a wall, and not sure where to go from here. Continue to get the same error Could not find or load main class Program. Any assistance will be greatly appreciated.

Code:

Write a console program that:
Uses a while loop to perform the following steps:
Prompt the user to kbInput two integers: firstNumber and secondNumber where secondNumber is at least 10 greater
than firstNumber, both numbers are positive integers, and secondNumber is less than 1000.
Verify that the user entered acceptable numbers, and if not, provide error feedback and prompt them again.
Output all results to a file in the same directory as the program, placing an appropriate
label between each section of output. Note that your program must be able to run repeatedly overwriting
the file from the previous run.
Output all odd numbers between firstNumber and secondNumber inclusive, one number per line.
Output the sum of all numbers between firstNumber and secondNumber exclusive.
Uses a for loop to perform the following steps:
Continue writing to the same file as before.
Write a label as before.
Output all numbers from secondNumber to firstNumber in a single line with commas separating the numbers.
Write the date and time as the last line in the file in the format yyyy-mm-dd hh:mm:ss.

if (firstNumber < 0) {System.out.println("Enter positive number "); } else if (firstNumber > 989) {System.out.println("Enter number less than 900"); } else {valid = true; } } catch (Exception e) {System.out.println("Enter numeric value");kbInput = new Scanner(System.in); } }valid = false; while (!valid) { try {valid = false;System.out.print("Enter second number :");secondNumber = kbInput.nextInt(); if (secondNumber < 0) {System.out.println("Enter positive number "); } else if (secondNumber > 1000) {System.out.println("Enter number less than 1000"); } else if ((secondNumber - firstNumber) < 10) {System.out.println("Second number should be at least 10 greater than first number"); } else {valid = true; } } catch (Exception e) {System.out.println("Enter numeric value");kbInput = new Scanner(System.in); } }FileWriter fileWriter = new FileWriter(new File("Assignment2.txt"));//Use a for loop to perform the following steps: //Continue writing to the same file as before. //Write ad label as before. //Output all odd numbers between firstNumber and secondNumber inclusive, one number per line.fileWriter.write("1. All odd numbers between firstNumber and secondNumber inclusive");fileWriter.write(System.getProperty("line.separator")); for (int i = firstNumber; i <= secondNumber; i++) { if (i % 2 != 0) {fileWriter.write(i + "");fileWriter.write(System.getProperty("line.separator")); } }//Output the sum of all numbers between firstNumber and secondNumber exclusive.fileWriter.write("2. The sum of all numbers between firstNumber and secondNumber exclusive");fileWriter.write(System.getProperty("line.separator"));int sum = 0; for (int i = firstNumber + 1; i < secondNumber; i++) {sum += i; }fileWriter.write(sum + "");fileWriter.write(System.getProperty("line.separator"));//Output all numbers from secondNumber to firstNumber in a single line with commas separating the numbers.fileWriter.write("3. All numbers from secondNumber to firstNumber in a single line with commas separating the numbers");fileWriter.write(System.getProperty("line.separator")); for (int i = firstNumber; i <= secondNumber; i++) {fileWriter.write(i + ","); }fileWriter.write(System.getProperty("line.separator"));//Write the date and time as the last line in the file in the format yyy-mm-dd hh:mm:ss.fileWriter.write("4. The date and time as the last line in the file in the format yyy-mm-dd hh:mm:ss");fileWriter.write(System.getProperty("line.separator"));fileWriter.write((new SimpleDateFormat("yyyy-mm-dd hh:mm:ss")).format(new Date()));System.out.println("File Assignment2.txt written");fileWriter.close(); }}

Overall it looks fine for me, and without any modifications I can run it to give me this as a result:

Code:

1. All odd numbers between firstNumber and secondNumber inclusive
5
7
9
11
13
15
2. The sum of all numbers between firstNumber and secondNumber exclusive
90
3. All numbers from secondNumber to firstNumber in a single line with commas separating the numbers
5,6,7,8,9,10,11,12,13,14,15,
4. The date and time as the last line in the file in the format yyy-mm-dd hh:mm:ss
2013-09-14 03:09:19

Which aside from the date format at the end being incorrect (it should either be 15:09 or 03:09 PM), looks good.

Is the problem when you are trying to compile / run the program? What's the full error you are getting? One thing to watch for are both the package naming when calling / compiling the java, as well as the file extensions (don't provide the extensions).

Edit:
BTW, on a side note, the date/time does actually match exactly what the requirements are. So you may want to confirm / verify that; I'd suggest it should be either 'HH:mm:ss' or 'hh:mm:ss a'

Last edited by Fou-Lu; 03-14-2013 at 10:17 PM.

PHP Code:

header('HTTP/1.1 420 Enhance Your Calm');

Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)