[Logo]
Forums Register Login
how to write a program that gives greatest number and least number
(0 likes, 1 cow)
this is what i did so far...any suggestions
Danny,
Have you learned about arrays or ArrayLists yet? If so, you can use a loop. Otherwise, you'll need to have 7 if statements (or call a method 7 times.)
can you either tell me where i can learn about arraylists or show me an example of how i could write 7 if statements (or call a method 7 times).
and can you also tell me if i am on the right track with the code that i posted earlier
 

Danny Alphones wrote:can you either tell me where i can learn about arraylists or show me an example of how i could write 7 if statements (or call a method 7 times).



Tutorials on arrays... https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html

Henry
thanks Henry Wong
Henry Wong how would i use an arraylists to get the greatest and least out of 7 numbers i did not really understand the concept.
I'm not Henry, but let's break it down. The first thing is to put all seven numbers in the ArrayList. Can you post how you do that?

Then you can rewrite the methods. To make the tasks simpler, can you write a method that takes an ArrayList parameter? How about one that returns the first element of the ArrayList?
i have never used arraylists ever so i do not know how to do even that.
This is one of the example without ArrayList. You can look at it



so in my case i would do the same process but 7 times right
 

Danny Alphones wrote:so in my case i would do the same process but 7 times right



From the code I given, the n used to represent how many process you want it to run

 
(1 like)
Ok, thanks, and also i will send you my modified code later so you can check it
 

Danny Alphones wrote:Ok, thanks, and also i will send you my modified code later so you can check it


No problem
this is my code but it only let me put 2 numbers
This is really close!


Since numb is 7, this is like writing:


Which means it should only loop once. What do you think would be good to set i to initially so it runs more than once?


The code not perfect yet. If user input 0 for the process, the result are wrong. But I leave it for you to modify 
7 sense i is repeating until it is more than 7
i dont think i can use the scanner because i am using a old version of eclipse and java so how would i do it other wise.  
 

Danny Alphones wrote:i dont think i can use the scanner because i am using a old version of eclipse and java so how would i do it other wise.  


I never use the old version of eclipse and java
the only reason i am using an old version is that i am learning from online free lectures on the Stanford website and it requires an old version of the two.
 

Danny Alphones wrote:the only reason i am using an old version is that i am learning from online free lectures on the Stanford website and it requires an old version of the two.



Why don't you follow the latest tutorial ?
(1 like)
because the latest tutorials are the intermediate ones not the beginner tutorials.(they were all recorded in the same year that is what i think at least but i am sure that there are no modern tutorials.) 
(1 like)
Note also that OP's program is extending this ConsoleProgram
yeah i found out that i could use a scanner if i wrote java.util.U*; instead of java.util.Scanner;
 

Danny Alphones wrote:yeah i found out that i could use a scanner if i wrote java.util.U*; instead of java.util.Scanner;


Glad to hear that 
 

Jeanne Boyarsky wrote:. . . it should only loop once. . . .

Are you quite sure about that? Please check carefully.
 

Danny Alphones wrote:i dont think i can use the scanner because i am using a old version of eclipse and java so how would i do it other wise.  

Scanner was introduced in 2004. Nobody ought to use a version of Java┬« so old that it doesn't have Scanner. If the tutorial you are using is old enough not to mention Scanner it shou‍ld not be used either.
 

Danny Alphones wrote:yeah i found out that i could use a scanner if i wrote java.util.U*; instead of java.util.Scanner;

That looks mistaken; I am pretty sure the first class name will fail to compile after import. Just because you can get away with imports ending * doesn't make them a good thing, anyway.

Anyway, if you are using Eclipse, then forget about imports and that sort of thing. You write something like
Sca ctrl-space and Eclipse will give you a dropdown list. That will have java.util.Scanner near its top, so you click (or maybe double‑click) Scanner and Eclipse will insert the import declaration for you in the correct place. You will not need to think about imports at all.
I think you have reached the stage where you need to resort to desperate measures.
  • 1: Get rid of the Stanford package and use ordinary Java┬« like everybody else. We cannot test your code because we lack the requisite .jar.
  • 2: Delete the entire class. I think you are going to have to start again.
  • 3: Turn your computer off.
  • Your code looks as if you were guessing. You can make 1,000,000 guesses and as long as they are all different, there is a good chance that one will be correct. Or you can think about your application and plan it and get it to work first time.
    You also need to be more careful what you are thinking about.

    About 12 hours ago, you wrote:7 sense i is repeating until it is more than 7

    That is incorrect. Look carefully at the operators.
    Learn the basic form of a for loop, and work out what the different numbers on the left and in the middle shou‍ld be.
  • 4: Write down on paper what you are going to do, and make the stages simpler and simpler. When you have got everything very simple, it will become easier to turn into code.
  • I believe your other threa‍d is so simlar to this one that I ought to merge the two.
    I merged your stuff with the following thread. I hope that is okay by you.
    when i run a java applet i am supposed to be able to put numbers and get both the greatest and the least(my class extends the ConsolProgram and i am learning from Stanford free online lectures)

    here is my code....

     
    Wink, wink, nudge, nudge, say no more ... https://richsoil.com/cards


    This thread has been viewed 90802 times.

    All times above are in ranch (not your local) time.
    The current ranch time is
    May 23, 2018 00:49:07.