Greeting.javaFrom WikiJava
This is a simple application that demonstrates how Input and Output is done in java programming.
the articleThis is a simple application that prompts the user for thier first name and last name the application then responds with 'Hello first & last name, what is the weather like today?' once the user has answered, the application should re[ly with 'Maybe tomorrow will be nicer'. input/output examplepackage org.wikijava.simpleIO; /** * @author (Alex Mutuku Mbolonzi) * @version (07/06/08) */ import java.io.*; public class Greeting { public static void main(String args[]) throws Exception { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String firstName = ""; String lastName = ""; String weather = ""; // The system prompts the user to enter their First Name /** * asks the first name until the user writes something */ while ("".equals(firstName)) { System.out.print("PLEASE ENTER YOUR FIRST NAME: "); firstName = in.readLine(); } /** * asks the last name until the user writes something */ while ("".equals(lastName)) { System.out.print("PLEASE ENTER YOUR LAST NAME: "); lastName = in.readLine(); } /** * Once the user has entered their first and last name the system * displays a greeting massage in upper case and prompts the user to * describe how the weather is like, the system then displays a massage * telling the user that maybe the weather will be better tomorrow. */ System.out.print("HELLO " + firstName.toUpperCase() + " " + lastName.toUpperCase()); System.out.print(", What is the Weather like today? "); weather = in.readLine(); System.out.print("Maybe tomorrow will be nicer."); } }
|

Thanks for sharing, I modified the names of your variables, it is good practice to avoid short names and acronyms. The results are more legible.
I also deleted the ifs using instead a while. There's no duplicate code now and the while prevents the Strings to be empty.
--DonGiulio 08:54, 17 September 2008 (PDT)