Results 1 to 3 of 3
- 01-14-2009, 06:34 AM #1
Member
- Join Date
- Jan 2009
- Posts
- 22
- Rep Power
- 0
Can somoene explain this to a noob?
Output:Java Code:public static void main(String[] args) { int[] myNum={476, 717, 33, 408, 9295}; int maxIndex = findMax(myNum); System.out.println("Max is= " +myNum[maxIndex] +" " +maxIndex); } public static int findMax(int[]num) { int maxNum=num[0]; int index=0; for(int i=0; i<num.length;i++) { if(num[i]>maxNum) { maxNum=num[i]; index=i; } } return index; } }
Max is= 9295 4
This code compiles and checks for the largest number in the array, the output shown is the maxnumber returned and the index number. I want to know why does the index number return 4, instead of 5?
-
What is the first index number of any Java array?
edit: hint: look at your for-loop. What indices does it use loop with?Last edited by Fubarable; 01-14-2009 at 06:37 AM.
- 01-14-2009, 06:37 AM #3
Member
- Join Date
- Jan 2009
- Posts
- 22
- Rep Power
- 0
Similar Threads
-
Please explain Java
By MarkWilson in forum New To JavaReplies: 7Last Post: 07-02-2008, 08:38 AM -
Need Help Can anyone explain what this means
By Clemenza1983 in forum New To JavaReplies: 6Last Post: 02-16-2008, 03:13 AM -
Can anyone briefy explain what does that mean?
By Clemenza1983 in forum New To JavaReplies: 6Last Post: 01-29-2008, 07:05 AM -
Iam new in Java Please explain to me
By vinaytvijayan in forum AWT / SwingReplies: 1Last Post: 12-30-2007, 11:35 AM -
need to explain this code
By reached in forum New To JavaReplies: 3Last Post: 12-03-2007, 10:01 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks