How Does this work?

0 Usama tariq · April 23, 2015

import java.util.Scanner;
public class TutorialClass {
    
    public static void main(String args[]){
        
        double sum;
        System.out.print("Enter Number 1 : ");
        Scanner xnot = new Scanner(System.in);
        //System.out.print(xnot.nextLine());
        System.out.print("Enter Number 2 : ");
        Scanner y = new Scanner(System.in);
    }    
        
    }


I actually wanted to make a program that add two numbers by taking input from user.

I am  a C++ programmer actually.How does the Java compiler works? It gives me output >>
Enter Number 1 :

Enter Number 2 :

And I cannot input something.Help.

Post a Reply

Replies

Oldest  Newest  Rating
0 Usama tariq · April 23, 2015
Okay thankyou.
0 Nicholas Eason · April 23, 2015
You create two scanners in your example. What you really need is to just make one, then call:

input = Scanner.nextLine();
//or for your case:
input = Scanner.nextInt();
0 Usama tariq · April 23, 2015
Can someone help please?
  • 1

Java / Android Development

107,255 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator