Results 1 to 4 of 4
Thread: quick help
- 10-23-2012, 07:42 PM #1
Member
- Join Date
- Jul 2012
- Posts
- 93
- Rep Power
- 0
quick help
Java Code:public static void main(String[] args) { int numIntegers = 5; int[] inputInts = new int[numIntegers]; Scanner scan = new Scanner(System.in); for (int i = 0; i < numIntegers; i++) { try { inputInts[i] = scan.nextInt(); System.out.println("Got integer input: " + inputInts[i]); } catch (InputMismatchException ime) { System.out.println("Got non-integer input: " + scan.nextInt()); } } } }
Can someone tell me whats wrong with this code?Last edited by jwl; 10-23-2012 at 07:50 PM.
- 10-23-2012, 08:06 PM #2
Re: quick help
You're going to have to tell us. Does it compile? Does it run? Does it throw an Exception? Generate incorrect output? Something else?
Have you stepped through this with a debugger, or at least added some print statements, to figure out what's going on?How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 10-23-2012, 08:10 PM #3
Member
- Join Date
- Sep 2012
- Posts
- 11
- Rep Power
- 0
Re: quick help
add this :
Java Code:public static void main(String[] args) { final int numIntegers = 5; // need to be a const int[] inputInts = new int[numIntegers]; Scanner scan = new Scanner(System.in); for (int i = 0; i < numIntegers; i++) { try { System.out.print("input "+i+" : "); inputInts[i] = scan.nextInt(); System.out.println("Got integer input: " + inputInts[i]); } catch (InputMismatchException ime) { System.out.println("Got non-integer input: " + scan.nextInt()); } } } }
- 10-24-2012, 04:52 AM #4
Re: quick help
Please go through the Forum Rules -- particularly the third paragraph.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
Should be a quick fix :)
By Alienz in forum New To JavaReplies: 5Last Post: 04-08-2011, 01:23 AM -
Quick Help!!
By MrA in forum New To JavaReplies: 1Last Post: 11-10-2010, 07:38 PM -
Quick help
By locazor in forum New To JavaReplies: 15Last Post: 10-17-2010, 07:07 PM -
Quick help
By Qwertypoiuy in forum New To JavaReplies: 5Last Post: 01-06-2010, 10:49 PM -
Need help quick!
By Manikyr in forum New To JavaReplies: 11Last Post: 01-28-2009, 04:08 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks