Categories

JAVA DATEBASE
Technology Network Community
Oracle Database
Fusion Middleware
Development Tools
Java
Desktop
Server & Storage Systems
Enterprise Management
Berkeley DB Family
Cloud Computing
Big Data
Business Intelligence
Architecture
Migration and Modernization
E-Business Suite
Siebel
PeopleSoft Enterprise
JD Edwards World
Industries
JD Edwards EnterpriseOne
User Productivity Kit Pro (UPK) and Tutor
Governance, Risk & Compliance (GRC)
Master Data Management (MDM)
Oracle CRM On Demand
On Demand: SaaS and Managed Applications
AutoVue Enterprise Visualization
Primavera
ATG
Agile PLM
Endeca Experience Management
Fusion Applications
Archived Forums

 



Tags

New To Java


I dont understand!!


Hey everyone i don't understand why counter < responses.length;  includes the 40th number in the array shouldn't it stop at the 39th number?  int responses [] = {1,2,6,4,8,5,9,7,8,10,1,6,3,8,6,10,3,8,2,7,6,5,7,6  		,8,6,7,5,6,6,5,6,7,5,6,4,8,6,8,10};  		  		int frequency [] = new int[11];  		  		for(int counter = 0;counter < responses.length;++counter)  		{  			++frequency[responses[counter]];  			  		}//end for loop 

You're pre-incrementing your counter variable.   Change it to:  		for(int counter = 0;counter < responses.length;counter++)  and see how it behaves then.

If length is 5, then the indices in the array are 0, 1, 2, 3, 4  4 < 5, so arr[4] (the 5th and last one) shows up.

You're pre-incrementing your counter variable.   Change it to: [code] for(int counter = 0;counter   < responses.length;counter++) /code] and see how it behaves then.  Absolutely irrelevant.  ++counter vs. counter++ does NOT cause the ++ to happen at a different point relative to the loop. It's simply that the value the ++counter expression is the incremented value of counter, and the value of the counter++ expression is the original value of counter. But that expression's value is not used anywhere, so it doesn't matter.

Absolutely irrelevant  You're correct, sir.   Just ignore me.  goes for coffee

What i don't understand is why if the counter is set to include everything less than 40 it includes 40 anyway.

What i don't understand is why if the counter is set to include everything less than 40 it includes 40 anyway.  Read Jverds reply. It is because you start from zero. 0 to 39 = 40 iterations. The loop runs 40 times.  Message was edited by:          kikemelly

What i don't understand is why if the counter is set to include everything less than 40 it includes 40 anyway.  Re-read reply 2. It doesn't include index 40. It includes arr[0] through arr[39]. That's 40 items.

Re-read reply 2. It doesn't include index 40. It includes arr[0] through arr[39]. That's 40 items.  OK i get it now thanks..


Related Links

Java to support Extended Protection for Integrated Authentication in win 7
Java Application
Global Object Creation
Object Refrence Problems
How to write a add() to make test work
Hi, I'm Dan
dont know how to fix the code
Using nio channels and map to move data to disk quickly
problem in out from for loop
Can you help me fix a two-class Fahrenheit-Celsius/vice-versa Java Program?
Help with a program
compare the value inside the Map
Help with passing arguments to cmd
Dynamically Reloading Classes
casting problem; making a nextFloat into an integer
uncaught exception: java.lang.reflect.InvocationTargetException