Java exercise?

April 27th, 2008 · 3 Comments

Download Our Brand New ACCELERATED Fat Loss Diet!

Hi, am new to java and have been given the following exercise. Can someone help me out:
'Write an application that prompts the user for their first name and then their last name. The application should then respond with 'Hello first & last name, what is the weather like today? Once the user has answered, the application should reply with 'Maybe tomorrow will be nicer'.

Related posts:

  • microsoft VB version 5 and 6, chapter 6 exercise 4 help please?
  • Crease an Initials application that allows the user to enter his or...
  • stack exercises java?!?
  • hey, i have a quiz tomorrow and i need exercises and quizzes about...
  • Java Help - Exercise?
  • It says something about no method named readInt was found in type...
  • Help in Java Exercise?
  • It says it needs a while statement, but there is one. import...
  • Java string exercise help please!?
  • Q1) Write a program that will find out if a given letter is in a...
  • Beginner's Java Exercises?
  • I want to try some exercises for beginners in Java so I can begin to...
  • Anyone have any creative writing exercises or prompts to share?
  • I know about the writing prompts at Writer's Digest, but I'm looking...
  • need help with some java exercises?
  • im trying to make a hangman essk program that i found in my book. i...
  • Help for Java Exercise?
  • Put the program in a loop that continues until the user decides to...
  • Creative writing exercise/prompt ideas?
  • I asked this a few days ago, but only one person answered, so I'm...

    Tags: Exercise



    3 responses so far ↓

    • 1 Ravi Chandra // Apr 27, 2008

      For this level of user interaction in Java, you need to use buffered I/O streams. You can look this up on google where you can get a lot of examples…

    • 2 Jackson // Apr 27, 2008

      import java.io.*;

      public class Simple {

      /**
      * @param args
      */
      public static void main(String[] args)
      {
      InputStreamReader isr = new InputStreamReader(System.in);
      BufferedReader input = new BufferedReader(isr);
      String line = "";
      String prompt = ("Input your first and last name, use "
      + "the Enter key after each name is input:\n");
      System.out.println(prompt);
      String strFirst = "";
      String strLast = "";
      try
      {
      strFirst = input.readLine();
      strLast = input.readLine();
      System.out.println( "Hello " + strFirst + " " + strLast + ", what is the weather like today?");
      input.readLine();
      System.out.println( "Maybe tomorrow will be nicer.");
      }
      catch(IOException ex)
      {
      ex.printStackTrace();
      }
      }

      }

    • 3 coding // Apr 27, 2008

      before you dive into stream chains and buffers, I recommend you to first consider java.util.Scanner class for taking simple input. For a beginner it is much easier to understand Scanner concept, rather than streams and buffers.
      e.g.:
      import java.util.Scanner;

      public class Interact{
      public static void main(String[]args){
      String first ="", last="";
      Scanner sc = new Scanner(System.in);
      try{
      System.out.println("Enter your first name, press enter to confirm");
      first = sc.nextLine();
      System.out.println("Enter your last name, press enter to confirm");
      last = sc.nextLine();
      }catch(Exception e){}
      System.out.format("Hello %1$s %2$s, what is the wheather like today?", first, last);
      }
      }

      this is not complete example but you'll get it finished…

    Leave a Comment

    *
    To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
    Click to hear an audio file of the anti-spam word

     

    Sitemap Powered by Yahoo!Answers! All rights reserved.