+ 2
how to receive only int values from the user?
want to recieve only int type data from user https://code.sololearn.com/ctw45s71Mg3Q/?ref=app
3 Respuestas
+ 31
import java.util.Scanner;
class Output
{
    public static void main(String[] args) 
    {
        String name="papa panther";
        int x=3,y=2;
        int sum=x+y;
        ++sum;
        String lo="black",ho="big";
        Scanner pap=new Scanner(System.in);
        System.out.println(x=pap.nextInt());
        if(x==10){
            System.out.println("too short");
        }
        System.out.print(name+lo+ho);
        System.out.println(sum);
        
    }
}
//try this ☺
//int x=pap.nextInt (); //to get user input as a integer
+ 8
The part of taking input is wrong. If pap is the Scanner object, then input should be taken like this:
int num = pap.nextInt();
+ 2
You can use hasNextInt() method. What you are going to do with this method is:
https://code.sololearn.com/c2nH9xaq3b23/#java
Apparently for some reason I don't know, the code doesn't work on SoloLearn. It works on NetBeans, try it on IDEs.



