Names - while (name00.compareTo(name11) > 0 ||

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

View Full Document Right Arrow Icon
public class Names { public static void main(String[] args) { String name0 = ""; String name1 = ""; String name2 = ""; for (int i = 0; i < 3; i++) { System.out.println("Enter a name: "); String name = IO.readString(); name = name.trim(); if (name.indexOf(",") == -1) { if (name.indexOf(" ") < 0 || name.indexOf(" ") > name.length()) { name = name; } else { int last = name.lastIndexOf(" "); name = name.substring(last+1); } } else { int index = name.indexOf(","); name = name.substring(0,index); } if (i == 0) name0 = name; else if (i == 1) name1 = name; else if (i == 2) name2 = name; } name0 = name0.trim(); name1 = name1.trim(); name2 = name2.trim(); String name00 = name0.toLowerCase(); String name11 = name1.toLowerCase(); String name22 = name2.toLowerCase(); String temp;
Background image of page 1

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

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

Unformatted text preview: while (name00.compareTo(name11) &gt; 0 || name11.compareTo(name22) &gt; 0) { int a = name00.compareTo(name11); if (a &gt; 0) { temp = name0; name0 = name1; name1 = temp; } int b = name11.compareTo(name22); if (b &gt; 0) { temp = name1; name1 = name2; name2 = temp; } name00 = name0.toLowerCase(); name11 = name1.toLowerCase(); name22 = name2.toLowerCase(); } name0 = name0.substring(0,1).toUpperCase() + name0.substring(1).toLowerCase(); name1 = name1.substring(0,1).toUpperCase() + name1.substring(1).toLowerCase(); name2 = name2.substring(0,1).toUpperCase() + name2.substring(1).toLowerCase(); IO.outputStringAnswer(name0); IO.outputStringAnswer(name1); IO.outputStringAnswer(name2); } }...
View Full Document

This note was uploaded on 11/03/2009 for the course CS 01-111 taught by Professor Pradiphari during the Fall '09 term at Rutgers.

Page1 / 2

Names - while (name00.compareTo(name11) &amp;amp;gt; 0 ||

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