Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package app;
- /**
- *
- * @author SC0U7
- */
- import java.util.Scanner;
- public class app {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- String pokracovat="ano";
- //Treba zadat text
- Scanner vstup = new Scanner(System.in);
- while (pokracovat.equals("ano"))
- {
- System.out.println("1=Sifrovat\n2=Desifrovat");
- int volba = Integer.parseInt(vstup.nextLine());
- switch(volba)
- {
- case 1:
- System.out.println("Zadaj text pre zašifrovanie: ");
- break;
- case 2:
- System.out.println("Zadaj text pre dešifrovanie: ");
- break;
- default:
- System.out.println("Zadal si zlu moznost!");
- System.exit(0);
- }
- String sprava = vstup.nextLine();
- sprava.trim();
- System.out.println("Zadaj posun (číslo): ");
- // premenne
- int posun=Integer.parseInt(vstup.nextLine());
- String nove=" ";
- int ascii=0;
- // cyklus
- for (char znacik : sprava.toCharArray())
- {
- if (volba==1)
- {
- ascii=(int)znacik+posun;
- nove += String.valueOf((char)ascii);
- }
- else
- {
- ascii=(int)znacik-posun;
- nove += String.valueOf((char)ascii);
- }
- }
- System.out.println(nove);
- System.out.println("Pokracovat [ano/nie]: ");
- pokracovat=vstup.nextLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement