Solved

Another incrementing problem

Posted on 2004-09-08
15
242 Views
Last Modified: 2006-11-17
Well guys I have another incrementing problem for you...this time it's a little more difficult but still pretty basic.   This problem gives me 6 canditates/bits of code to fill in for a single line and 6 outputs.  In this book I'm supposed to match the bit of code to one of the outputs.  

Canditates:               Correct Outputs:
x = x + 3;                      54 6
x = x + 6;                      60 10
x = x + 2;                      45 6
x++;                             36 6
x--:                               18 6
x = x + 0;                      6 14

Now the Code:
class MixFor5 {
    public static void main(String [] args) {
        int x = 0;
        int y = 30;
        for (int outer = 0; outer < 3; outer++) {
            for (int inner = 4; inner > 1; inner--) {
                x = x + 0; // THE BIT OF CODE YOU REPLACE WITH POSSIBLE CANDIDATES
                y = y - 2;
                if (x == 6) {
                    break;
                }
                x = x + 3;          
            }
            y = y - 2;
        }
        System.out.println(x+ " " + y);  
    }
}

Please just go through the code so that I can understand why the output is what it is.  You don't have to do it through every possible candidate...just pick one you think will help me understand this.  Thanks a lot
0
Comment
Question by:Ringitup
  • 5
  • 4
  • 3
  • +1
15 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 12009124
This is beginning to look more like classwork Ringitup ...
0
 

Author Comment

by:Ringitup
ID: 12010733
No I bought a book this summer, "Head First Java" and it's one of the problems in the book.  They give you the problem and the answers but I just needed an explanation so I can understand it a bit better.  
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12011136
Well i can't be bothered working it out - someone else will. But i will say that torturing yourself with this stuff is not really going to be very profitable for you, apart from perhaps getting you used to reading other people's bad code, but even then, you should never come across code as bad as that (of that type) in the real world. There are plenty of better things to be learning, such as how to design programs well, but of course it's harder to write books about that ...
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:Ringitup
ID: 12011245
Well I'm in a Data Structures course which is very java intensive and I happen to have the Anti-Christ as a professor.  Anyway, I'm doing what I can to make sure that I can understand coded programs which I'm hoping will help me write my code.  The other java books I have takes you from one concept to another so abruptly that I didn't have time to learn this years ago which is why I'm in this situation.  Let me know what you suggest so I can pass this last Java course I have for my major.  
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12011600
>>Let me know what you suggest so I can pass this last Java course I have for my major.  

Well of course, if you have 'for loop tricks' as part of the syllabus, and you've seen that such problems could appear in the exam, then of course you must practise them. My comments were based on your implication that you were embarked on some sort of self-study ;-)
0
 
LVL 92

Expert Comment

by:objects
ID: 12012180
We offer an excellent tutoring service if you're interested, haven't had student fail yet :)

0
 

Author Comment

by:Ringitup
ID: 12012802
I think I'm beyond help but it sounds good to me
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 12015238
Again I suggest that you download an IDE (ECLIPSE or so) so that you can see what happens
to those variables step by step, and you don't need us anymore.
;JOOP!
0
 

Author Comment

by:Ringitup
ID: 12018493
I tried getting Eclipse from the Eclipse sight but every time I went to unzip the download file it said there was an error and I should check it out in "C:Documents"  I'm trying to find other ways of getting it but I haven't found any as of yet.  If you know of any let me know.  Thanks again
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 12018705
It is about 90 Mb. Does your disk overflow?
And it should just be unzipped into a directory, say C:/eclipse to work.
May be you should follow their advise and select a mirror to download from.
If you are in the far east, load it from JAPAN or so.

;JOOP!
0
 

Author Comment

by:Ringitup
ID: 12021602
I downloaded the file again and I created a folder on my C: drive called Eclipse.  I then extracted the files in this folder but I still received an error when I clicked the .exe file.  It says, "An error has occured.  See the log file C:\Eclipse\eclipse\configuration\.... I checked the log file but it was a bunch of jiberish that makes no sense.  I have installed other IDE's so this isn't a new thing.  I'm not sure what else it could be. Disk overflow is not a problem.  Anything else?
0
 
LVL 24

Accepted Solution

by:
sciuriware earned 80 total points
ID: 12023926
I made a shortcut containing:

E:\ECLIPSE\eclipse.exe -data D:\JOOP\JAVA\workspace

and it works like hell.
Before that I installed JAVA JRE 1.4       did you?

;JOOP!
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 12246120
Thanks ....
I mean agreed!
;JOOP!
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
xampp tool 12 56
eclipse buid path vs tomcat lib path 10 34
Convert from a json string array to a Java object 3 53
Crystal Reports Licensing Questions 4 34
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question