Thursday, February 18, 2010

Console Input Sample Program

Java Console Input Program

import java.util.*;

/**
* This program demonstrates console input.
*/

public class InputTest
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);

// get first input
System.out.print("What is your name? ");
String name = in.nextLine();

// get second input
System.out.print("How old are you? ");
int age = in.nextInt();

// display output on console
System.out.println("Hello, " + name + ". Next year, you'll be " + (age + 1));
}
}


0 comments:

About This Blog

  © Blogger templates The Professional Template by Ourblogtemplates.com 2008

Back to TOP