CSE 17 Test 1 FALL 2005

CSE 17 Test 1 FALL 2005 - CSE 17 Test 1 Tuesday 18 October...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CSE 17 Test 1 Tuesday 18 October 2005 <<<<<<<<<<<<<<<<<<<<<<<<<<SUGGESTED ANSWERS>>>>>>>>>>>>>>>>>>>>>>>>> 1. Write a program that prompts the user to enter four strings from the console and then displays the lexicographically (as they would appear in a case-sensitive dictionary) smallest and largest string. <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< HERE ARE TWO SUGGESTED ANSWERS: import java.util.Scanner; public class MinMax4 { public static void main(String[] args) { Scanner scan=new Scanner(System.in); String [] four=new String [4]; String min,max; System.out.print ("Enter four strings each separated by at least one blank or tab\n"); for(int j=0;j<4; j++) four[j]=scan.next(); min=four[0]; max=four[0]; for(int j=1; j<4; j++) {if(min.compareTo(four[j])>0) min=four[j]; if(max.compareTo(four[j])<0) max=four[j]; } System.out.println ("The lexicographically smallest is '"+min+ "', the largest is '"+max+"'"); } } <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/05/2008 for the course CSC 017 taught by Professor Edkay during the Spring '08 term at Lehigh University .

Page1 / 4

CSE 17 Test 1 FALL 2005 - CSE 17 Test 1 Tuesday 18 October...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online