previous | start | next

Formated printing of Strings

    1   public class Max3 {
    2   
    3    
    4     public static void main(String[] args) {
    5       String s1, s2, s3;
    6       String max;
    7       Scanner input = new Scanner(System.in);
    8       ....
    9       max = s1;
   10       if ( s2.compareTo(max) > 0  ) {
   11         max = s2;
   12       }
   13       if (s3.compareTo(max) > 0 ) {
   14         max = s3;
   15       }
   16       System.out.printf("For strings '%s', '%s', and '%s', %s comes last in the usual ordering.",
   17           s1, s2, s3, max);
   18       
   19     }
   20   }


previous | start | next