/* Programmer: Maribelle Lacno
* Program name: NameEcho
* Subject: IT134_Computer Programming 3
* Instructor: Mr. Dony Dongiapon
* Date Started: 03/16/09
* Date Finished: 03/18/09
* Purpose: To write a program that will asks for user's
* name and then writes it back with the first name
* as entered, and the second name all in capital letters.
*/
import java.util.*;
import java.io.*;
public class NameEcho{
public static void main(String[] args)throws StringIndexOutOfBoundsException{
try{
Scanner scan = new Scanner(System.in);
//ask the user to input data.
System.out.println("Enter your name:");
//get the data and store it in variable name.
String name = scan.nextLine();
//get the index of " " through indexOf method
int c=name.indexOf(" ");
int a=c+1;
//store the first name entered to variable output
String output = name.substring(0,c);
//store the second name entered to variable name2
String name2=name.substring(a,name.length());
//print the first name and the second name in capital letters
System.out.print(output+" "+name2.toUpperCase());
}
catch(StringIndexOutOfBoundsException index){
System.err.printf("No more data.");
}
}
}
Friday, March 20, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment