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

Java

 
GeneralRe: Problem Array and looping Ip address,How? Pin
terry.schoof25-Jul-13 10:31
professionalterry.schoof25-Jul-13 10:31 
GeneralRe: Problem Array and looping Ip address,How? Pin
Richard MacCutchan25-Jul-13 21:06
mveRichard MacCutchan25-Jul-13 21:06 
GeneralRe: Problem Array and looping Ip address,How? Pin
terry.schoof26-Jul-13 8:25
professionalterry.schoof26-Jul-13 8:25 
QuestionNeed help to capture signature on a tablet Pin
Mehwish Wajiuddin16-Jul-13 20:55
Mehwish Wajiuddin16-Jul-13 20:55 
Questionthe problem about when tomcat was installed as a NT service Pin
xiaobai137916-Jul-13 16:51
xiaobai137916-Jul-13 16:51 
AnswerRe: the problem about when tomcat was installed as a NT service Pin
jschell17-Jul-13 8:45
jschell17-Jul-13 8:45 
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 
Hi!! I'm trying to understand the sharpen your pencil Class Puzzle4 from head first java.. But the math and the logic is confusing me... I hope someone can give me some explanation before I move on in the book... The output of the code should be Result 543345

Java
 public class Puzzle4 {
	public static void main (String[] args){
		
		Puzzle4b[] obs = new Puzzle4b[6];
		
		int y = 1;
		int x = 0;
		int result = 0;
		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);
			
		}
		x = 6;
		System.out.println(" x = " + x);
		while (x > 0){
			x = x - 1;
			System.out.println(" x = " + x);
			System.out.println("obs[x].doStuff(x) = " + obs[x].doStuff(x));
			result = result + obs[x].doStuff(x);
		}
		System.out.println("Result " + result);
	}
	
   

}
class Puzzle4b {
	int ivar;
	
	
	public int doStuff(int factor){
		if (ivar > 100){
			System.out.println("ivar = " + ivar);
			return ivar * factor;
		}
		else{
			return ivar * ( 5 - factor );
		}
	}
	
	
}

What isreturn ivar * ( 5 - factor );????
ivar is an instance and the value of it is unique to every object is that right?? The logic of the method is confusing me. I understand that x is the argument to

modified 15-Jul-13 17:27pm.

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 
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 

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.