Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package javaapplication1;
- /**
- *
- * @author Danny
- */
- //import scanner//
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args)
- {
- //Variables//
- int orig;
- int result;
- int digit1, digit2, digit3,digit4;
- int number = 0;
- //Import scanner, here, and above.//
- System.out.print("Enter a four digit number: ");
- Scanner keyboard = new Scanner(System.in);
- orig = keyboard.nextInt();
- //I used a do-while statement.
- do {
- // Code for encryption//
- //For the first digit, this will be applied//
- orig = orig % 1000;
- orig= orig + 7;
- digit1 = orig % 10;
- //For the second digit, this will be applied//
- orig = orig % 1000;
- orig = orig % 100;
- orig = orig+7;
- digit2 = orig % 10;
- //For the third digit, this will be applied//
- orig = orig % 10;
- orig = orig+7;
- digit3 = orig % 10;
- //For the fourth digit, this will be applied//
- orig = orig+7;
- digit4 = orig % 10;
- //Swap first and third digits//
- digit2 = digit4;
- digit1 = digit3 * 1000;
- digit3 = orig * 10;
- //Swap second and fourth digit//
- orig = digit2;
- digit2 = digit4 * 100;
- digit4 = orig;
- //The result is//
- result = digit1 + digit2 + digit3
- + digit4 ;
- //Print the result (Encrpted number)//
- System.out.println("The Encrypted number is:" +result);
- } while (number>0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement