Thank you for this, but I actually figured it out yesterday after I deleted all of it and started over.
Now, I have another simple issue but I didn't want to take up space and make a whole new thread for it.
Basically, I want encrypt to equal Tencrypted3, Tencrypted4, Tencrypted1, Tencrypted2, in that order.
The goal of this assignment is to have the user enter a four digit number, and then separate each number individually. Add seven to each single digit, then divide by 10 and replace the original digit with this new one. We then swap digit 1 & 3, as well as digit 2 & 4. Afterwards, we are to reverse the process to get back to the original number.
I have it completed all the way up to getting the mixed up number. My issue is getting the mixed up number stored as its own int, so I can then use it to reverse the process. It's probably super obvious, but nothing I've tried has worked. That's all I need, nothing more.
import java.util.Scanner;
public class Encrypt
{
public static void main( String args[] )
{
Scanner input = new Scanner(System.in );
int number;
int number1;
int number2;
int number3;
int number4;
int ecrypted;
int encrypted1;//These are used for the first step in encryption, adding 7
int encrypted2;
int encrypted3;
int encrypted4;
int Tencrypted1;//These are used for the second step in encryption, getting remainder
int Tencrypted2;//It seems like there's probably a more efficient way to achieve this but it works
int Tencrypted3;
int Tencrypted4;
number = 99999;
while (number >= 9999 || number <= 999)
{
System.out.print("Please enter a four digit number: ");
number = input.nextInt();
if (number >= 9999)
{
System.out.println("That's not a four digit number.\n");
}
if (number <= 999)
{
System.out.println("That's not a four digit number.\n");
}
}
number4 = number % 10;
number3 = number / 10 % 10;
number2 = number / 100 % 10;
number1 = number / 1000 % 10;
encrypted1 = number1 + 7;
encrypted2 = number2 + 7;
encrypted3 = number3 + 7;
encrypted4 = number4 + 7;
Tencrypted1 = encrypted1 % 10;
Tencrypted2 = encrypted2 % 10;
Tencrypted3 = encrypted3 % 10;
Tencrypted4 = encrypted4 % 10;
System.out.printf("\nBAM:\n%d%d%d%d", Tencrypted3, Tencrypted4, Tencrypted1, Tencrypted2);
encrypted =
input.close();
}
}
There's probably a much more convenient way to set up this code as well, but I'm not worried about efficiency in this case. My goal is only to make it work.