that code that i have problem with it is only accept 2 input from me y and how to solve it please

Scanner keyboard = new Scanner(System.in);
String IP = keyboard.nextLine();
String TTL = keyboard.nextLine();
Scanner kb = new Scanner(System.in);
String conntype = kb.nextLine();

thanks in advance

Recommended Answers

All 8 Replies

Why do you create two Scanners?

Why do you create two Scanners?

because when i do that
Scanner keyboard = new Scanner(System.in);
String IP = keyboard.nextLine();
String TTL = keyboard.nextLine();
String conntype = keyboard.nextLine();

i also have the same problem

Since two scanners didn't fix it, roll back to having just one.
The code in your last post should run OK - what exactly happens when you run it?

Since two scanners didn't fix it, roll back to having just one.
The code in your last post should run OK - what exactly happens when you run it?

that what's happen

Enter 3 values:

10.0.0.2
123
Exception in thread "main" java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:470)
at java.lang.Integer.parseInt(Integer.java:499)
at IP2HC_Inspect.main(IP2HC_Inspect.java:14)

Process completed.

sorry that what's happen

Enter 3 values:

10.0.0.3
128

Process completed.

OK. That tells you the problem is nothing to do with your Scanner.
It's always important to read carefully what the Exception messages say. They usually tell you exactly what the problem is and where. In this case:
It's a NumberFormatException. You can look that up in the API JavaDoc to find exactly what it means. In this case, tried to parse a String as an integer but the String did not have the right format for a number because it was empty ("").
It happened in the Integer.parseInt method which you called at line 14 of your main method of IP2HC_Inspect.
(No, I'm not psychic - all that is in the error message you posted.)

That should be enough info for you to be able to find your problem.

ps: Typed that before I saw your later post without the Exception. So now you enter two lines (and a blank line I presume?) and your program terminates without error. Not much I can do about that.
Put lots of print statements into your code so you can see which blocks of code are being executed and what the values of your variables are. If you do enough of these you will find your problem.

that was sooo beatuful
i wiil try it and tell u thank u very much
best regards

sooooooooooo much thanks, it was solved, i do that
Scanner keyboard = new Scanner(System.in);
System.out.println("ip is");
String IP = keyboard.nextLine();
System.out.println("ttl is");
String TTL = keyboard.nextLine();
System.out.println("conn is");
String conntype = keyboard.nextLine();

u r so clever
thank u very much
with best regards

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.