# Help with printing prime numbers and their tenth

**843789**May 28, 2010 2:18 PM

Hi all,

I am in need of help, I want a program that accepts input from user and checks if that number is a prime, if its a prime then the program should print the Tenth of the number, I have Trouble print this in my main class, i am not good in Java. Here's What i have done so far.

I am in need of help, I want a program that accepts input from user and checks if that number is a prime, if its a prime then the program should print the Tenth of the number, I have Trouble print this in my main class, i am not good in Java. Here's What i have done so far.

```
package quiz;
import java.io.IOException;
/**
*This class checks if a given number is a Prime.
* @author Tonata
*/
public class Check extends AbstractCheck {
private String tenth;
private int primeNumber;
public Check() {
}
public Check(String tenth, int primeNumber) {
setTenth(tenth);
setPrimeNumber(primeNumber);
}
public String getTenth() {
return tenth;
}
public void setTenth(String tenth) {
this.tenth = tenth;
}
public int getPrimeNumber() {
return primeNumber;
}
public void setPrimeNumber(int primeNumber) {
this.primeNumber = primeNumber;
}
@Override
public boolean checkIfPrime(int number, int half) throws IOException, NumberFormatException, NullPointerException {
half = number / 2; //Store half of the given number
//loop through all the numbers below the half of the given number
for (int i = half; i >= 1; --i) {
if (number % i == 0) { // if the reminder of the given number divided by a number below half is equal to 0
return false;
}
}
return true;
}
/**
* abstract method to print the tenth of the given prime number
* @param tenth - 10th value of the number to be checked if its a prime
* @param int - prime number.
* @return tenth - String representation of the 10 of the number
*/
@Override
public String printTenthOfPrime(int primeNumber, String tenth) {
tenth = this.getTenth();
primeNumber = this.getPrimeNumber();
try {
int divisorInt;
int modulus;
if (checkIfPrime(primeNumber, primeNumber / 2)) {
if (primeNumber <= 10) {
if (primeNumber < 5) {
tenth = "Tenth of " + primeNumber + "is 0";
} else if ((primeNumber >= 5) && (primeNumber <= 10)) {
tenth = "Tenth of " + primeNumber + "is 10";
}
} else {
divisorInt = primeNumber / 10;
modulus = primeNumber % 10;
if (modulus < 5) {
tenth = "Tenth of " + primeNumber + "is" + divisorInt * 10 + "";
} else {
tenth = "Tenth of " + primeNumber + "is" + (divisorInt + 1) * 10 + "";
}
}
}
} catch (IOException ex) {
ex.printStackTrace();
} catch (NumberFormatException ex) {
ex.printStackTrace();
} catch (NullPointerException ex) {
ex.printStackTrace();
}
return tenth;
}
}
```

Now I don't know how to print in my main, How do i call the methods from this class. - 71 Views
- Tags: none (add)