c17f05t1 - CSE 17 Test 1 Tuesday 18 October 2005

Info icon This 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; i public class MinMax4 { p 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+"'"); } } <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< import java.util.Scanner; public class MinMax4a { public static void main(String[] args) { Scanner scan=new Scanner(System.in); String one,two,three,four; System.out.println ("Enter four strings, separated by blanks or tabs, and"
Image of page 1

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern