Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Shavit Borisov
- // CW
- import java.util.Scanner;
- public class SecretCode {
- public static void main(String[] args)
- {
- Scanner in = new Scanner (System.in);
- char ch;
- int length;
- boolean direction = true;
- System.out.print("Enter the length of your secret code: ");
- length = in.nextInt();
- System.out.print("Enter your secret code letter by letter and divide words with '!':");
- ch = in.next().charAt(0);
- for(int i = 0; i < length; i++)
- {
- if (ch == '!')
- direction = !direction;
- else
- {
- if(direction)
- ch++;
- else if (!direction)
- ch--;
- }
- System.out.printf("%c\n", ch);
- System.out.print("Enter your next letter: ");
- ch = in.next().charAt(0);
- }
- System.out.println("Goodbye!");
- in.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement