import java.util.Scanner;

public class primenumbertest {
    public boolean isPrime(int num){
    int x;
    Scanner input = new Scanner(;
    System.out.print("Enter a number to find out if it's prime or not  (greater than 1): ");
 	num = input.nextInt();
    if (num == 2) return true;
    // check for divisible by all even number
    if (num % 2 == 0) return false;
    // check for odd number only
    	for (int i = 3; i < num; i=i+2){
        	if (num % i == 0) return false;
    	return true;  // all test pass..number is prime

Beginner to Java. Getting the error, java.lang.NoSuchMethodError: main... Exception in thread "main"

A way to fix this?


You are missing a main function in the program.

public void main(String[] args)
Thanks for the help. (:

Yeah i figured that out. Thanks i just need to know where it goes...

The code will go right after your class declaration so you have:

public class primenumbertest {
public static void main(String[] args) {

You will have to put another bracket to match the other at the end.

This question has already been answered. Start a new discussion instead.