Advertisement
Shavit

P. 200 Ex. 7.63

Nov 17th, 2013
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.80 KB | None | 0 0
  1. // Shavit Borisov
  2. // CW
  3.  
  4. import java.util.Scanner;
  5.  
  6. public class SecretCode {
  7.  
  8.     public static void main(String[] args)
  9.    
  10.     {
  11.         Scanner in = new Scanner (System.in);
  12.        
  13.         char ch;
  14.         int length;
  15.         boolean direction = true;
  16.        
  17.         System.out.print("Enter the length of your secret code: ");
  18.         length = in.nextInt();
  19.        
  20.         System.out.print("Enter your secret code letter by letter and divide words with '!':");
  21.         ch = in.next().charAt(0);
  22.        
  23.         for(int i = 0; i < length; i++)
  24.         {
  25.             if (ch == '!')
  26.                 direction = !direction;
  27.             else
  28.             {
  29.                 if(direction)
  30.                     ch++;
  31.                 else if (!direction)
  32.                     ch--;
  33.             }
  34.             System.out.printf("%c\n", ch);
  35.            
  36.             System.out.print("Enter your next letter: ");
  37.             ch = in.next().charAt(0);
  38.         }
  39.        
  40.         System.out.println("Goodbye!");
  41.        
  42.         in.close();
  43.     }
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement