Shavit

Ex. Bank #23

Dec 7th, 2013
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.68 KB | None | 0 0
  1. // Shavit Borisov
  2. // HW
  3.  
  4. import java.util.Scanner;
  5.  
  6. public class TwoDigitChecker {
  7.  
  8.     public static void main(String[] args)
  9.    
  10.     {
  11.         Scanner in = new Scanner (System.in);
  12.        
  13.         int num, firstDigit, secondDigit;
  14.        
  15.         System.out.print("Enter a two digit number: ");
  16.         num = in.nextInt();
  17.        
  18.         firstDigit = num % 10;
  19.         secondDigit = num / 10;
  20.        
  21.         if(num % 2 == 0)
  22.         {
  23.             firstDigit++;
  24.             if(secondDigit == 9)
  25.                 secondDigit = 0;
  26.             else
  27.                 secondDigit++;
  28.         }
  29.         else
  30.         {
  31.             firstDigit--;
  32.             if(secondDigit == 0)
  33.                 secondDigit = 9;
  34.             else
  35.                 secondDigit--;
  36.         }
  37.        
  38.         System.out.printf("Your new number is %d%d", secondDigit, firstDigit);
  39.        
  40.         in.close();
  41.     }
  42. }
Add Comment
Please, Sign In to add comment