Scanner Class Example:
| package com.first; import java.util.Scanner; public class InputDataReading { // in this program we will take user input // we will ask user age as input parameter. // based on user age we will display the result. // lets start public static void main(String[] args) { System.out.println("************ User Data Taking from Input***************"); System.out.println("Enter Age:"); Scanner sc = new Scanner(System.in); int age = sc.nextInt(); if(age >= 18){ System.out.println("Your Age is -->"+ age +" You are eligilble for voting"); } else { System.out.println("Your Age is -->"+age+" " +"You are not eligible for voting"); System.out.println("Please wait for ****"+(18-age)+"****"+"years for voting"); // now we will execute the program //short cut for executing the Java Standalone Program is "CTRL+F11" } } } |
Output:




0 comments:
Post a Comment