Advertisement
Guest User

WIBU

a guest
Nov 15th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.22 KB | None | 0 0
  1. package woche03;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Aufgabe7 {
  6.    
  7.     static Scanner z = new Scanner(System.in);
  8.     static Scanner w = new Scanner(System.in);
  9.    
  10.     public static void main(String[] args) {
  11.  
  12.         System.out.print("Số vị trí phải dịch chuyển: ");
  13.         int zahl = z.nextInt();
  14.        
  15.         System.out.print("Nhập từ khóa: ");
  16.         char[] wort = w.nextLine().toCharArray();
  17.        
  18.         System.out.println("Số vị trí phải dịch chuyển là: " + zahl);
  19.        
  20.         for (int i = 0; i < wort.length; i++) {
  21.            
  22.             if (Character.isLowerCase(wort[i])) {
  23.                
  24.                 wort[i] = (char) (wort[i] + zahl);
  25.                   if (wort[i] > 'z') {
  26.                     wort[i] = (char) (wort[i] - 26);
  27.                 }
  28.                
  29.             } else if (Character.isUpperCase(wort[i])) {
  30.                
  31.                 wort[i] = (char) (wort[i] + zahl);
  32.                 if (wort[i] > 'Z') {
  33.                     wort[i] = (char) (wort[i] - 26);
  34.                 }
  35.                
  36.             }
  37.            
  38.             // Ausgabe
  39.             System.out.print(wort[i]);
  40.            
  41.         }
  42.        
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement