Your code is confusing with two local variables called num and numb.
Danny Alphones wrote:Campbell Ritchie can you tell me where i can learn java more than Stanford since you suggested i should not use stanford.
I think more modern approaches can be found on this website and in the books that this website recommends:
Try thisThat code should compile and run on any Java® installation. Eclipse should have no difficulty with it. Once you have got it running, delete line 11 and you code in the run() method. I suggest you do this:-Now you will get red marks on Eclipse because that code won't compile. Click each red mark and you get a dropdown list of options to correct it, including create method.... Click that. Now you need to fill in those three methods. You will probably need smallest and largest fields.
Now, you will have a more object‑oriented result than you had previously. You should be designing the code step by step; having those three methods will make it easier to go step by step. If you use Eclipse it will organise the imports for you, as I said earlier.
Danny Alphones wrote:
Now you create the smallest and largest fields and write the logic behind each step. It's going to be a fun ride, don't worry.
what do you mean by Smallest and larges fields and write the logic behind each step
could you show me an example of that.
I mean you should define two fields named Smallest and Largest.
The logic behind steps means the code inside each method. You should basically replace the // TODO Auto-generated method stub with your own code in each method. For example in printResults() you will write the code that prints out the results generated in the previous methods.
Danny Alphones wrote:i am sorry i am a real beginner to java so when you say "you will write the code that prints out the results generated in the previous methods." i have no idea how to do that i just started java a few weeks ago i consider it a miracle that when somebody talks about a scanner or a if statement or a for loop or while loop i know half of what they are talking about.
Okay so then your first step before you even consider solving the problem is understanding how to write methods, what they are...same goes for basic stuff: learn about if statements and loops. Then you can come back with real knowledge to solve this problem and post your solution in this thread.
Change the how many numbers method to read how many from the keyboard. It will print, “How many numbers do you want?” and you enter 7 and it will return 7. You can use the same code you had earlier with a Scanner or you can use this Stanford class, which appears to be much more useful than the Stanford code you have been using.
Add the following line to the run() method:-
System.out.printf("You are going to use %d numbers.%n", count);
* * * * * * * * *
Now remove that last print line and get the printResults method working. As I said, you will need two fields, and until you have the middle method working, it will simply print 0, 0. Or -2147483648, 2147483647. But don't worry about that. You will sort that out with the middle method.
I think the problem here is that you are trying to solve a Java problem -- and it isn't. It is a logic problem. You need to understand the logic before you can put it to code.
In other words, if I write down a bunch of numbers on a piece of paper, can you tell me what is the greatest number and smallest number? Can you describe how were you able to obtain the greatest number and smallest number? And finally, can you describe the procedure to a five year old child, to find the greatest number and smallest number?
I think, once you are able to accomplish that on paper, should you try convert that to pseudo code, and ultimately to Java. Otherwise, you are just putting random code snippets together, with the hope that the end result works.
Danny Alphones wrote:ok than can you tell me where i can learn about basics(beside orcal.)
You have been given a link to the Java™ Tutorials, which show how to write a method. You should be able to find out about methods in any Java® book. But Eclipse has already written much of the method for you. I hope you used my naughty trick with the red marks.
Danny Alphones wrote:by the way John Joe i have seen your post earlier and wanted to ask one thing how much did the book help vs. the one semester at the university.
I think it would be better if we discuss at here or private message.
Campbell Ritchie wrote:Why are you supposed to use console program? I do not think it is helping you at all. Please don't say applet when you are not using an applet.
As I pointed out in a previous reply, OP is extending this https://cs.stanford.edu/people/eroberts/jtf/javadoc/student/acm/program/ConsoleProgram.html which is, in fact, a subclass of Applet.