ans to :
1. using brute force to calculate i used:

if ( num <= 1 )
return false;
// calculates through 2 to num to find the prime numbers
for ( int prime = 2; prime <= num; prime++ )
{
if ( num % prime == 0 )
return false;
}
return true;
}

2.Not exactly sure but below is my code

for( int prime = 2; prime <= Math.sqrt(n); prime++) {
if( n % prime == 0 ){
return false;
}
}
return true;

Correct me if I am wrong. Your prime must be less than number not less than or equal to number. This is because if prime and number are equal, then it will always return false and will never return true. Also, line 10 of your 1st solution should be outside of the for loop. Else it will only do the check once.

Eventually prime and num variable will be equal. Once they are equal, the if statement where the num % prime will be true eventually and will always return false.

> for ( int prime = 2; prime <= num; prime++ )
> {
> if ( num % prime == 0 )
> return false;
> }
> }

Other way to spot this is to see that there is no possibility for the function to return true (or at least not zero) value, so you have also another fix to make.

Hey, so I wanna ask how I need to create a method who will remove word if in that word is 2 same chars. Example: "Potato" in this word there is a 2 "o" chars so this word will need to be removed. "Forum" in this word there is no ...

Help! I want to create a java program that finds the highest even integer among the values entered by the user. Stop asking values when a value less than 1 have been entered. If no even integer is entered, display "No Even Integer"

I am writing a java program that needs to execute shell commands, so I wrote a function that would take the command to execute as a string (ie: "mkdir ~/Folder1") and execute that command with the shell. Here is the function:

try
{
Runtime run = Runtime.getRuntime();
Process pr = ...