![]() When the program is run, it asks the user to enter a name. The entered name is then displayed on the screen by statement #8. Statements #5 and #6 ask the user to enter a name that is then assigned to the string name. Statement #4 defines a try.catch block to check for any errors that might have occurred while the reader entered the text. Statement #3 uses the istream reader to convert the data into string form. The entered text is stored in the form of Unicode characters. The reader will read from the standard input stream ( System.in) that is, from the keyboard. Statement #2 creates a reader called istream. In WelcomeMsg.java, statement #1 imports the packages required for input/output operations. InputStreamReader istream = new InputStreamReader(System.in) #2īufferedReader bufRead = new BufferedReader(istream) #3 ![]() For example, if the user enters the name "Kelly," the message, "Welcome Kelly!" appears on the screen. After entering the name, when the user presses Enter, a welcome message appears, including the name the user typed. The code shown in Listing 1 is a simple Java program called WelcomeMsg.java that asks the user to enter a name. Learn More Buy Example: A Simple Java Program
0 Comments
Leave a Reply. |