• Home
  • About
  • Contact
  • Privacy Policy
  • Home
  • About
  • Contact
  • Privacy Policy

code with zaheer

java reading data from keyboard
  • java
  • reading data from keyboard

reading data from keyboard

Posted on August 13, 2022
codewithzaheer

To read the input values in java

Scanner class is used to read data from keyboard, and it is from util package.

below program "addition of two numbers"

package basics;

import java.util.Scanner;

public class readFromKeyboard {

public static void main(String[] args) {

Scanner read = new Scanner(System.in);

int FirstNumber;

int SecondNumber;

int Result;

System.out.println("enter first number");

FirstNumber = read.nextInt();

System.out.println("enter second number");

SecondNumber = read.nextInt();

Result = FirstNumber + SecondNumber;

System.out.println("the result is " + Result);

}

}


note:

To know the methods present in that scanner class we have the command javap java.util.Scanner

To check it open the command prompt and enter the command, then you will get the list of methods present in the scanner Class.

Some of the methods are listed below

nextInt()

nextFloat()

nextDouble()

next()

nextLine()

nextBoolean()

nextByte()

nextShort()

nextLong()

etc...

No comments:

Post a Comment

Newer Post Older Post Home
Subscribe to: Post Comments (Atom)

Popular Posts

  • Guide to testing your local website on mobile devices: Simple steps for developers
  • python syllabus
  • A Deep Dive into Angular modules

Quick Links

  • Home
  • About
  • Contact
  • Privacy Policy

Follow us on

This website is developed by Zaheer Introvert © 2021