import java.util.Scanner;

public class primenumbertest {
	
    public boolean isPrime(int num){
    
    int x;
    
    Scanner input = new Scanner(System.in);
    	
    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?

Thanks!

Recommended Answers

All 4 Replies

You are missing a main function in the program.

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

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.

Thanks I changed some things and I got it (:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.