Advertisement
Guest User

lancuchy-znakow-zadania-all

a guest
Nov 23rd, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.00 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package javaapplication65;
  7.  
  8. import static java.lang.Boolean.TRUE;
  9. import java.util.Scanner;
  10.  
  11. public class JavaApplication65 {
  12.     public static void main(String[] args) {
  13.         /*
  14.         Scanner wprowadz = new Scanner(System.in);
  15.         String x;
  16.         int y, z, numer;
  17.         z = 1;
  18.        
  19.         System.out.print("Wprowadz: ");
  20.         x = wprowadz.nextLine();
  21.         y = x.charAt(x.length()-1);
  22.        
  23.         for(int i=0; i<x.length()-1; i++) {
  24.            
  25.             numer = x.charAt(i);
  26.            
  27.             if (numer==y) {
  28.                 z++;
  29.             }
  30.            
  31.         }
  32.         System.out.println("Ostatni char powtarza sie: " + z + " razy");
  33. */ // ---------------------------------------------------------------- //
  34. /*
  35.         Scanner wprowadz = new Scanner(System.in);
  36.         String x;
  37.         String napis = "";
  38.         int y;
  39.         System.out.print("Wprowadz: ");
  40.         x = wprowadz.nextLine();
  41.        
  42.         for (int i=x.length()-1; i>=0; i--) {
  43.             y = x.charAt(i);
  44.             napis += (char)y;
  45.            
  46.            
  47.     }
  48.        
  49.         System.out.println(napis);
  50.        
  51.         */ // ----------------------------------------------- //
  52.  /*      
  53.         Scanner wprowadz = new Scanner(System.in);
  54.         String x;
  55.         int y = 0;
  56.         int sprawdz = 0;
  57.         int sprawdz2 = 0;
  58.         System.out.print("Wprowadz: ");
  59.         x = wprowadz.nextLine();
  60.        
  61.         for(int i=0; i<(x.length())/2; i++) {
  62.             y = x.charAt(x.length()-1-i);
  63.             if (x.charAt(i) == y){
  64.                 sprawdz += 1;
  65.             } else {
  66.                 sprawdz2 += -1;
  67.             }
  68.                
  69.            
  70.         }
  71.         if (sprawdz>0 && sprawdz2 == 0) {
  72.             System.out.println("TAK");
  73.         } else {
  74.             System.out.println("NIE");
  75.     }
  76. */
  77.     /* ---------------------------------------
  78.         Scanner wprowadz = new Scanner(System.in);
  79.         String x;
  80.         int y = 0;
  81.         int z = 0;
  82.         int suma = 0;
  83.         System.out.print("Wprowadz: ");
  84.         x = wprowadz.nextLine();
  85.        
  86.         for (int i=0; i<x.length(); i++) {
  87.            
  88.            
  89.             if(Character.isDigit(x.charAt(i)) == TRUE) {
  90.                 y = Character.getNumericValue(x.charAt(i));
  91.                 z += y;
  92.             }
  93.            
  94.         }
  95.         System.out.println("Wynik: " + z);
  96.        
  97.     */ // ----------------------------------------------
  98.     /*
  99.         Scanner wprowadz = new Scanner(System.in);
  100.         String x;
  101.         int y = 0;
  102.         int z = 0;
  103.         System.out.print("Wprowadz: ");
  104.         x = wprowadz.nextLine();
  105.        
  106.         for (int i=0; i<x.length(); i++) {
  107.             if (x.charAt(i) == '(') {
  108.                 z++;
  109.             }
  110.             if (x.charAt(i) == ')') {
  111.                 y++;
  112.             }
  113.         }
  114.         if (z!=y) {
  115.             System.out.println("Niepoprawna liczba nawiasow");
  116.         } else {
  117.             System.out.println("POPRAWNA liczba nawiasow");
  118.         }
  119.         */ // --------------------------------------
  120.         Scanner wprowadz = new Scanner(System.in);
  121.         String x;
  122.         String nowy = "";
  123.         int n = 0;
  124.        
  125.         int y = 0;
  126.         System.out.print("Wprowadz ciag: ");
  127.         x = wprowadz.nextLine();
  128.         System.out.print("Wprowadz przesuniecie: ");
  129.         n = wprowadz.nextInt();
  130.    
  131.         for (int i=0; i<x.length(); i++) {
  132.             int charnum = x.charAt(i)+n;
  133.             if(charnum<'a') {
  134.                 charnum += 26;
  135.             }
  136.             if(charnum>'z') {
  137.                 charnum -= 26;
  138.             }
  139.            
  140.             char c = (char)charnum;
  141.             nowy += c;
  142.         }
  143.        
  144.         System.out.print("Wynik szyfru: " + nowy);
  145.  
  146. }
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement