Friday, March 20, 2009

NAME ECHO

EXERCISE 4

/* Programmer: Nerissa Agapay
* Program name: NameEcho
* Instructor: Mr. Dony Dongiapon
* Date Started: 03/16/09
* Date Finished: 03/18/09
* Description:To capitalize the second name enter by the user.
*/
import javax.swing.*;
import java.io.*;

public class NameEcho{
public static void main(String[] args)throws StringIndexOutOfBoundsException{
try{


String name=(JOptionPane.showInputDialog("Enter your name:"));//ASK THE USER
/

int c=name.indexOf(" ");
int a=c+1;
String name2=name.substring(a,name.length());
String output = name.substring(0,c);
System.out.print(output+" "+name2.toUpperCase());//print the input and the second name all in capital letters

}
catch(StringIndexOutOfBoundsException index){//error handling
System.err.printf("No more index follow.");//print messsage
}
}
}

No comments:

Post a Comment