TheBulgarianWolf

Encription method example

Apr 6th, 2020
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.16 KB | None | 0 0
  1. package softuni;
  2.  
  3.  
  4. import java.util.Scanner;
  5.  
  6.  
  7.  
  8. public class SoftUni {
  9.          
  10.     static String encriptionMethod(int amount){
  11.         Scanner sc = new Scanner(System.in);
  12.         String text = "";
  13.         int count = 0;
  14.         while(count < amount){
  15.             char letter = sc.next().charAt(0);
  16.             int ascii = (int)letter;
  17.             String asciiStr = Integer.toString(ascii);
  18.             char first = asciiStr.charAt(0);
  19.             int firstInt = Integer.parseInt(String.valueOf(first));
  20.             int lastInt = ascii%10;  
  21.             char comb1 = (char) (ascii+lastInt);
  22.             char comb2 = (char) (ascii-firstInt);
  23.            
  24.             String text1 = comb1 + (Integer.toString(firstInt)+ "" + Integer.toString(lastInt)) + comb2;
  25.             text += text1;
  26.             count++;
  27.          }
  28.         return text;
  29.     }
  30.    
  31.    
  32.     public static void main(String[] args){
  33.         Scanner sc = new Scanner(System.in);
  34.         System.out.print("Enter the amount of numbers here: ");
  35.         int amount = Integer.parseInt(sc.nextLine());
  36.         System.out.println(encriptionMethod(amount));
  37.        
  38.        
  39.     }
  40.    
  41. }
Add Comment
Please, Sign In to add comment