0

i am a first year student and i dont have a clue whats going on. i keep getting this error:Exception in thread "main" java.lang.NoSuchMethodError: main
this is the code i am using but i dont think its releated to this.

public class reverse
{
	public static void main (String [] args)
	{
		int [] numbers = new int [5];

		System.out.println("Enter 5 numbers:");

		for(int i=0; i<5; i++)
			numbers [i] = Console.readInt();
		for(int i=4; i>=0; i--)	
			System.out.println(numbers[i] + " " );
		for(int i=0; i<5; i++)
			System.out.println(numbers[i] + " " );
		
	}
}
3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by Abdel_eid
0

I am pretty sure you do know this, but Java is probably one of the few languages that the name of file that you wrote your program in is related to the code inside it.

To provide an example, in your case, the name of the file should be reverse.java. Casing is also important, so be aware!!

Secondly, I modified your code in this way, have a look:

import java.util.Scanner;
public class reverse
{
        public static void main (String [] args)
        {
                int[] numbers = new int [5];
                Scanner in = new Scanner(System.in);

                System.out.println("Enter 5 numbers:");

                for(int i=0; i<5; i++)
                        numbers[i] = in.nextInt();
                for(int i=4; i>=0; i--)
                        System.out.println(numbers[i] + " " );
                for(int i=0; i<5; i++)
                        System.out.println(numbers[i] + " " );

        }
}
0

ronan since you are new to this ,leaving the for loop without braces or the curly brackets as they said :) as not a good coding style so get used to bracket every thing that needs it because later you will find it so much better

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.