Use Euclid's algorithm to find the greatest common factor. This algorithm is much simpler to program than the method taught in school (the method that involves finding prime factors). If the greatest common factor is 1, the numbers are relatively prime.
package javaapplication1;
public class JavaApplication1 {
public static boolean is_prime(int val){
if (val<0) val*=-1;
if (val<2) return false;
if (val%2==0) return val==2;
int max = (int)Math.sqrt(val)+1;
for (int div=3; div<max; ++div)
if (val%div==0)
return false;
return true;
}
public static int next_prime(int val) {
do {
++val;
} while (!(is_prime(val)));
return val;
}
public static int prev_prime(int val) {
do {
--val;
} while (!(is_prime(val)));
return val;
}
public static void main(String[] args) {
System.out.print ("List of primes from -50 to 50:\n");
for (int i=-50; i<=50; ++i){
if (is_prime(i)) {
System.out.print (i);
System.out.print (" is prime\n");
}
}
System.out.print ("The next prime after -42 is ");
System.out.println (next_prime(-42));
System.out.print ("The previous prime before -42 is ");
System.out.println (prev_prime(-42));
}
}
Loop through some numbers - for example, 2 through 100 - and check each one whether it is a prime number (write a second loop to test whether it is divisible by any number between 2 and the number minus 1). If, in this second loop, you find a factor that is greater than 1 and less than the number, it is not a prime, and you can print it out.
No, 'check' is not a keyword in java language.
That is used to verify whether an object is based on the specified class (or a subclass).
yes
I think you mean Java Script, if so. you can download it or check to see if it is installed at www.java.com .
Find a prime number, add 2 to the number. Check if the new number is prime. IE : 3 is prime. 3+2 =5. 5 is prime. (3,5) are twin primes.
Loop through some numbers - for example, 2 through 100 - and check each one whether it is a prime number (write a second loop to test whether it is divisible by any number between 2 and the number minus 1). If, in this second loop, you find a factor that is greater than 1 and less than the number, it is not a prime, and you can print it out.
No, 'check' is not a keyword in java language.
where to start? do you have an algorithm and just want to implement it in java? depends on how big N is, as that will determine which method is most efficient
That is used to verify whether an object is based on the specified class (or a subclass).
Check the documentation of the String class, for a method that searches for a substring.
Go to the command line by typing "cmd" into the window opened with run on the start menu. the enter "java" and press enter. If you have java installed it will tell you the different options you can use on the command line and if it is not installed then it will come up with an error message.
It depends what you regard as being "special". Once you define the criteria for "special" you can formulate an algorithm that determines whether or not a given number meets that criteria. For instance, if you regard prime numbers as being special, you need a predicate to test whether a given number is zero, prime or composite. If prime then it is indeed special, otherwise it isn't. A predicate is a function that returns true or false depending on its input(s). As a simple example, if we regard even numbers as being special, then we need to test if the number has the prime factor 2. If so, it is special, otherwise it is not. We can test this by dividing the number by 2 and testing the remainder. If the remainder is zero, the number is even and is therefore special. We use the modulo operator (%) to determine the remainder after integer division: bool is_even (int n) { return (n % 2) == 0; }
The easiest way to check which version of Java is running on a computer is to ask Java directly. The website Java Tester has conveniently provided an applet which finds and displays the Java version currently used by the computer.
/* Program to Find whether number is Prime or Not. */ class PrimeNo{ public static void main(String args[]){ int num = Integer.parseInt(br.readLine()); int flag=0; for(int i=2;i
Check the link below for the Java entry in Answers.com.
i dont there is java tsunami but i have heard of meteotsunami and megatsuanmi but do check for it