Advertisement
Shavit

P. 181 Ex. 7.29

Nov 5th, 2013
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.66 KB | None | 0 0
  1. // Shavit Borisov
  2. // CW
  3.  
  4. import java.util.Scanner;
  5.  
  6. public class AlonVsBenny {
  7.  
  8.     public static void main(String[] args)
  9.    
  10.     {
  11.         Scanner in = new Scanner (System.in);
  12.        
  13.         char ch;
  14.         int votesForAlon = 0, votesForBenny = 0;
  15.        
  16.         System.out.println("Enter the votes string:");
  17.        
  18.         for(ch = in.next().charAt(0); ch != '#'; ch = in.next().charAt(0))
  19.         {
  20.             switch(ch)
  21.             {
  22.             case 'A':
  23.                 votesForAlon++;
  24.                 break;
  25.             case 'B':
  26.                 votesForBenny++;
  27.                 break;
  28.             default:
  29.                 break;
  30.             }
  31.         }
  32.        
  33.         if(votesForAlon > votesForBenny)
  34.             System.out.println("Alon won!");
  35.         else
  36.             System.out.println("Alon didn't win!");
  37.            
  38.         in.close();
  39.     }
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement