Note that there are some explanatory texts on larger screens.

plurals
  1. POtrying to limit the user to only entering a prime number
    primarykey
    data
    text
    <p>im creating an application that encodes and decodes messages. Im using RSA cryptography so i need to work with prime numbers. Ive figured out how to tell if the numbers are prime or not with a method</p> <pre><code>public int checkPrime(int number) { //Is this number greater than 0 for(int i = number-1; i &gt; 0; i--) { if((number % i) == 0) { if(i == 1) { System.out.println("is a prime"); isPrime = true; } else { System.out.println("is not a prime"); isPrime = false; } break; } } return number; } </code></pre> <p>So this prints out if its prime or not. But what i want to do is to keep asking the user for a number if it is not prime. I ask the user to enter the input in a class called MenuMethods and then its response is set to variables which then create an instance of the Encrypt class.</p> <pre><code>//--------------------------------------------------------------------------------------- // Name: userInput // Description: This method is used in the MainApp to give the user capability to enter // the details when adding details of an employee into the store. //--------------------------------------------------------------------------------------- public static Encrypt userInput() { //String temp = keyboard.nextLine(); Encrypt encrypt = new Encrypt(); System.out.println("Please enter the Public Key: "); int publicKey = keyboard.nextInt(); encrypt.checkPrime(publicKey); System.out.println("Please enter the Private Key: "); int privateKey = keyboard.nextInt(); encrypt.checkPrime(privateKey); return encrypt = new Encrypt(publicKey,privateKey); } </code></pre> <p>Can someone please help me with this....</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload