Getting User Input in Java

 package com.company;

import java.util.Scanner;


public class tuts {

    public static void main(String[] args) {

        System.out.println("Taking input from the user:");

        Scanner sc = new Scanner(System.in);

        System.out.println("Enter number 1: ");

        int a = sc.nextInt();

        System.out.println("Enter number 2: ");

        int b = sc.nextInt();

        int sum = a+b;

        System.out.println("The Sum of the numbers you had entered is :");

        System.out.println(sum);

//        boolean b1 = sc.hasNextInt();

//        System.out.println(b1);

    }

}


Comments

Popular posts from this blog

Creating a Thread by Extending Thread class

Constructors from Thread class in Java