Advertisement
SC0U7

Untitled

Aug 9th, 2013
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.60 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package app;
  6.  
  7. /**
  8.  *
  9.  * @author SC0U7
  10.  */
  11.  
  12. import java.util.Scanner;
  13. public class app {
  14.  
  15.     /**
  16.      * @param args the command line arguments
  17.      */
  18.     public static void main(String[] args) {
  19.       String pokracovat="ano";
  20.      //Treba zadat text
  21.      Scanner vstup = new Scanner(System.in);
  22.      while (pokracovat.equals("ano"))
  23.      {
  24.      System.out.println("1=Sifrovat\n2=Desifrovat");
  25.      int volba = Integer.parseInt(vstup.nextLine());
  26.      switch(volba)
  27.      {
  28.          case 1:
  29.              System.out.println("Zadaj text pre zašifrovanie: ");
  30.              break;
  31.          case 2:
  32.              System.out.println("Zadaj text pre dešifrovanie: ");
  33.              break;
  34.          default:
  35.          System.out.println("Zadal si zlu moznost!");
  36.          System.exit(0);
  37.      
  38.      }
  39.      String sprava = vstup.nextLine();
  40.      sprava.trim();
  41.      System.out.println("Zadaj posun (číslo): ");
  42.      // premenne
  43.      int posun=Integer.parseInt(vstup.nextLine());
  44.      String nove=" ";
  45.      int ascii=0;
  46.      // cyklus
  47.      for (char znacik : sprava.toCharArray())
  48.      {
  49.          if (volba==1)
  50.          {
  51.         ascii=(int)znacik+posun;
  52.         nove += String.valueOf((char)ascii);
  53.          }
  54.          else
  55.         {
  56.         ascii=(int)znacik-posun;
  57.         nove += String.valueOf((char)ascii);  
  58.         }
  59.      }
  60.      
  61.      System.out.println(nove);
  62.      System.out.println("Pokracovat [ano/nie]: ");
  63.      pokracovat=vstup.nextLine();
  64.      }
  65.     }
  66.    
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement