In this article I would like to share with you a sample program that I wrote using Java as my programming language to ask the users name and age and then our program will greet our user and display the users name user scanner class to accept input from our user. The code is very short and easy to understand.
Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com.
My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.
My mobile number here in the Philippines is 09173084360.
Sample Program Output
Program Listing
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication1;
import java.util.Scanner;
/**
*
* @author Jacob pomperada
* Example of Scanner Class in Java
* January 9, 2017 Monday
*/
public class JavaApplication1 {
public static void main(String args[]) {
Scanner input=new Scanner(System.in);
System.out.print("\t Scanner Class Demo in Java ");
System.out.println("\n");
System.out.print("Enter your Name : ");
String user =input.nextLine();
System.out.print("Enter your Age :");
int age=input.nextInt();
System.out.println();
System.out.print("Hi " + user + " Your age is " + age +" years old.");
System.out.println("\n");
System.out.println("\t End of Program");
System.out.println();
}
}
No comments:
Post a Comment