Advertisement
Shavit

P. 17 Ex. 9.11

Dec 24th, 2013
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.57 KB | None | 0 0
  1. // Shavit Borisov
  2. // CW
  3.  
  4. import java.util.Scanner;
  5.  
  6. public class LongestString {
  7.  
  8.     public static void main(String[] args)
  9.    
  10.     {
  11.         Scanner in = new Scanner (System.in);
  12.        
  13.         String input;
  14.         String longest = "";
  15.        
  16.         System.out.print("Keep entering strings. Stop the process by entering 'stop':\n");
  17.        
  18.         do
  19.         {
  20.             input = in.nextLine();
  21.             if((!(input.equals("stop"))) && (input.length() > longest.length()))
  22.                 longest = input;
  23.         }
  24.         while(!(input.equals("stop")));
  25.        
  26.         System.out.printf("Your longest string was:\n%s", longest);
  27.        
  28.         in.close();
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement