Click here to Skip to main content
15,888,096 members
Home / Discussions / Java
   

Java

 
GeneralRe: the problem about when tomcat was installed as a NT service Pin
xiaobai137918-Jul-13 20:01
xiaobai137918-Jul-13 20:01 
QuestionTrying to understand Puzzle4..Head First Pin
Skytten15-Jul-13 7:00
Skytten15-Jul-13 7:00 
AnswerRe: Trying to understand Puzzle4..Head First Pin
Richard MacCutchan15-Jul-13 22:12
mveRichard MacCutchan15-Jul-13 22:12 
GeneralRe: Trying to understand Puzzle4..Head First Pin
Skytten16-Jul-13 0:02
Skytten16-Jul-13 0:02 
GeneralRe: Trying to understand Puzzle4..Head First Pin
Richard MacCutchan16-Jul-13 0:14
mveRichard MacCutchan16-Jul-13 0:14 
GeneralRe: Trying to understand Puzzle4..Head First Pin
Skytten16-Jul-13 5:12
Skytten16-Jul-13 5:12 
GeneralRe: Trying to understand Puzzle4..Head First Pin
Richard MacCutchan16-Jul-13 5:16
mveRichard MacCutchan16-Jul-13 5:16 
GeneralRe: Trying to understand Puzzle4..Head First Pin
terry.schoof26-Jul-13 8:42
professionalterry.schoof26-Jul-13 8:42 
Skykitten,

First of all, you would do well in life not to antagonize someone whom is trying to help you. Not cool.

Second, you act like the code was so easy for someone out-of-context to understand and you can't get the jist of it? If it is so simple why are you here asking what it is?

Let's take a look at your code:
while (x < 6){
			
			obs[x] = new Puzzle4b();
			obs[x].ivar = y;
			System.out.println("obs[x] = " + obs[x].ivar);
			y = y * 10;
			System.out.println(" Y = " + y);
			x = x + 1;
			System.out.println(" x = " + x);
			
		}

This particular part initializes 6 instances of the Puzzle4b class and assigns them to parts of an array(obs[x]). with each increment(loop), y(which is used to initialize the ivar integer here) is incremented by multiples of 10. so for each instance created: 1, 10, 100, 1000...etc. this ivar is for the calculation done here:
Java
public int doStuff(int factor){
		if (ivar > 100){
			System.out.println("ivar = " + ivar);
			return ivar * factor;
		}
		else{
			return ivar * ( 5 - factor );
		}


when this method is called(horrible name by the way, dostuff? really?) it is called upon each instance, which causes the calculations to be unique to each instance. ie obs[1]'s ivar = 10, so 10 is used when I call the dostuff method on that particular instance. so on and so forth. The factor variable is nothing more than the name assigned to the variable passed to the method so that it can do the calculation and send it back to your main thread for printing.

at this point, since you were being a bit brash, i digress. Figure the rest out by RTFM.

Good day.
GeneralRe: Trying to understand Puzzle4..Head First Pin
Richard MacCutchan26-Jul-13 21:57
mveRichard MacCutchan26-Jul-13 21:57 
GeneralRe: Trying to understand Puzzle4..Head First Pin
terry.schoof27-Jul-13 8:05
professionalterry.schoof27-Jul-13 8:05 
QuestionConnection String for clients machine. Pin
chdboy10-Jul-13 17:16
chdboy10-Jul-13 17:16 
AnswerRe: Connection String for clients machine. Pin
AlphaDeltaTheta10-Jul-13 20:02
AlphaDeltaTheta10-Jul-13 20:02 
QuestionRe: Connection String for clients machine. Pin
Richard MacCutchan10-Jul-13 21:10
mveRichard MacCutchan10-Jul-13 21:10 
AnswerRe: Connection String for clients machine. Pin
jschell11-Jul-13 9:00
jschell11-Jul-13 9:00 
GeneralRe: Connection String for clients machine. Pin
chdboy16-Jul-13 19:26
chdboy16-Jul-13 19:26 
QuestionSynchronize JSP Pin
lyngocquy9-Jul-13 23:15
lyngocquy9-Jul-13 23:15 
AnswerRe: Synchronize JSP Pin
Shubhashish_Mandal10-Jul-13 2:14
professionalShubhashish_Mandal10-Jul-13 2:14 
GeneralRe: Synchronize JSP Pin
lyngocquy10-Jul-13 16:24
lyngocquy10-Jul-13 16:24 
GeneralRe: Synchronize JSP Pin
Zoidberg Why Not10-Jul-13 18:04
professionalZoidberg Why Not10-Jul-13 18:04 
QuestionMessage Closed Pin
9-Jul-13 21:02
realolap9-Jul-13 21:02 
QuestionDeveloping SaaS in Java Pin
Sarmad Hash8-Jul-13 10:19
Sarmad Hash8-Jul-13 10:19 
AnswerRe: Developing SaaS in Java Pin
Richard MacCutchan8-Jul-13 21:25
mveRichard MacCutchan8-Jul-13 21:25 
GeneralRe: Developing SaaS in Java Pin
Sarmad Hash19-Jul-13 9:28
Sarmad Hash19-Jul-13 9:28 
GeneralRe: Developing SaaS in Java Pin
Richard MacCutchan19-Jul-13 21:54
mveRichard MacCutchan19-Jul-13 21:54 
Questionnew to java - NullPointerException error Pin
Suzy McLain7-Jul-13 12:15
Suzy McLain7-Jul-13 12:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.