Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package woche03;
- import java.util.Scanner;
- public class Aufgabe7 {
- static Scanner z = new Scanner(System.in);
- static Scanner w = new Scanner(System.in);
- public static void main(String[] args) {
- System.out.print("Số vị trí phải dịch chuyển: ");
- int zahl = z.nextInt();
- System.out.print("Nhập từ khóa: ");
- char[] wort = w.nextLine().toCharArray();
- System.out.println("Số vị trí phải dịch chuyển là: " + zahl);
- for (int i = 0; i < wort.length; i++) {
- if (Character.isLowerCase(wort[i])) {
- wort[i] = (char) (wort[i] + zahl);
- if (wort[i] > 'z') {
- wort[i] = (char) (wort[i] - 26);
- }
- } else if (Character.isUpperCase(wort[i])) {
- wort[i] = (char) (wort[i] + zahl);
- if (wort[i] > 'Z') {
- wort[i] = (char) (wort[i] - 26);
- }
- }
- // Ausgabe
- System.out.print(wort[i]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement