Redirect input to console read - Java Language Basics

Java examples for Language Basics:int

Description

Redirect input to console read

Demo Code

import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner keyboard = new Scanner(System.in);
    int val;
    System.out.print("Enter an integer please:");
    val = keyboard.nextInt();
    val *= val; // squared the input value
    System.out.println("Squared value=" + val);
  }//from  w ww . j a va 2 s .c o  m
}

Result


Related Tutorials