So I have created a program to tell whether a number is a prime number or not. I basically did this by finding the modulus of the number with all numbers less than it. If the modulus is 0 for any number then isPrime = true. It runs fine up until I ask for another number to be tested. It won't let me type anything into the command line to re-run it...
import java.util.Scanner; public class primeNum { public static void main(String[] args){ boolean repeatPrime = true; while (repeatPrime){ Scanner in = new Scanner(System.in); boolean isPrime = false; System.out.println("Please enter a number"); //Sets the number to be tested for primality int testNumber = in.nextInt(); //Finds the modulus of all numbers less than the number being tested (except 1). for(int index = 2; index < testNumber; index++){ if ((testNumber % index) == 0){ isPrime = true; } } if (isPrime){ System.out.println("This is a prime number!"); } else{ System.out.println("This is not a prime number."); } //Repeat the test? System.out.println("Do you want to test another number? (yes/no)"); String inputRepeat = in.nextLine(); if (inputRepeat == "yes"){ repeatPrime = true; } else { repeatPrime = false; } } } }