Java tutorial
//package com.java2s; /* * Copyright (C) 2012 Joakim Persson, Daniel Augurell, Adrian Bjugard, Andreas Rolen * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class Main { /** * Finds out if a number is a prime number or not. * * @param number * The possible prime number * @return If it is a prime number or not */ public static boolean isPrime(int number) { if (number < 2) { return false; } if (number == 2) { return true; } if (number % 2 == 0) { return false; } int root = (int) Math.sqrt((double) number); for (int j = 2; j <= root; j++) { if (number % j == 0) { return false; } } return true; } }