I'm having trouble implementing 3 methods to create a program that checks if a number is prime. When I call my methods and run the program the only value that shows is 0
. I'm assuming this has to do with variables or logic in my methods
I have tried using different variables to store user input then using that variable as an argument in my methods.
package practice;
import java.util.Scanner;
public class Practice {
static Scanner s = new Scanner(System.in);
public static void main(String[] args) {
//int result = 0 ; //stores number user picks
int numPicked = 0; //
int endResults = 0; //stores result of calculation
// Calling methods
isPrime(numPicked);
pickedNum(numPicked);
results(endResults);
}
// Method to check if numbers are prime
public static boolean isPrime(int numPicked){
if (numPicked <= 1) {
return false;
}
for (int i = 2; i <= numPicked; i++) {
if (numPicked % i == 0) {
return false;
}
}
return true;
}
// Method that asks user for a positive integer
public static int pickedNum (int userNumbers){
Scanner s = new Scanner(System.in);
System.out.println("Type a positive number that you want to know if it's prime or not.");
int numPicked = s.nextInt();
return numPicked;
}
// Method that displays result of calculation
public static int results (int numPicked){
if(numPicked == 0 && numPicked != 1 ){
System.out.println( numPicked + " is a Prime Number");
}
else{
System.out.println(numPicked + " is Not a Prime Number");
}
return numPicked;
}
}
I need to fix the logic within my methods to be able to call them correctly.