Wednesday, March 27, 2013

Java;Notes - 13.) Input and Output

Made simple, Input is the act of gathering data from users. As well output is displaying that data. To do this with a terminal is really really simple:

Getting Input(Johny5) and Giving Output:
In order to get input we use a thing called a Scanner which basically takes input from the system and stores it into a scanner variable Here is how to use it:

  1. import Scanner
  2. Scanner input = new Scanner(System.in)
  3. System.out.print(What would you like to output: ") // This causes the cursor to show on this line
  4. String inStr = input.nextLine();
  5. System.out.println(inStr);
Here is the above example in use:

No comments:

Post a Comment