Friday, December 14, 2012

Java Tutorial 3 Source Code

import java.util.Scanner; public class Tutorial { public static void main(String[] args) { Scanner kb = new Scanner(System.in); byte age; String name; System.out.println("How old are you? "); age = kb.nextByte(); Scanner kb1 = new Scanner(System.in); System.out.println("What's your name? "); name = kb1.nextLine(); char c = name.charAt(0); System.out.println("You are " + age + " years old. Your name is " + name + "."); } }

4 comments:

  1. What exactl does the "Scanner" command do? Does it tell the program to look for input from an outside source and the "kb" narrows it down to the keyboard? How would I tell it to look for input from something like a mouse or a joystick?

    ReplyDelete
    Replies
    1. Scanner is used to retrieve data from users' inputs via keyboard and it can also retrieve data from a text file. The "kb" does not narrow it to keyboard, because it's a variable and you can name it anything you want it to be called. That syntax that I wrote above is meant to retrieve data from keyboard input only. If you want an input from a mouse, then you would need to use "Mouse listener" for that.

      Delete
  2. hi i just want to ask a favor can i do this scanner in if else statement will you please help me

    ReplyDelete
  3. javac is not recognized as internal or external command, operable program or batch file. why ? :'(

    ReplyDelete