• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to write a program that gives greatest number and least number

 
Ranch Hand
Posts: 52
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is what i did so far...any suggestions
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.)
 
Danny Alphones
Ranch Hand
Posts: 52
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
 
Danny Alphones
Ranch Hand
Posts: 52
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
and can you also tell me if i am on the right track with the code that i posted earlier
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Danny Alphones
Ranch Hand
Posts: 52
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Henry Wong
 
Danny Alphones
Ranch Hand
Posts: 52
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Danny Alphones
Ranch Hand
Posts: 52
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have never used arraylists ever so i do not know how to do even that.
 
Ranch Hand
Posts: 570
3
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is one of the example without ArrayList. You can look at it



 
Danny Alphones
Ranch Hand
Posts: 52
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so in my case i would do the same process but 7 times right
 
John Joe
Ranch Hand
Posts: 570
3
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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

 
 
Danny Alphones
Ranch Hand
Posts: 52
1
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, thanks, and also i will send you my modified code later so you can check it:)
 
John Joe
Ranch Hand
Posts: 570
3
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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


No problem
 
Danny Alphones
Ranch Hand
Posts: 52
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is my code but it only let me put 2 numbers
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
John Joe
Ranch Hand
Posts: 570
3
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


The code not perfect yet. If user input 0 for the process, the result are wrong. But I leave it for you to modify  
 
Danny Alphones
Ranch Hand
Posts: 52
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
7 sense i is repeating until it is more than 7
 
Danny Alphones
Ranch Hand
Posts: 52
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.  
 
John Joe
Ranch Hand
Posts: 570
3
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Danny Alphones
Ranch Hand
Posts: 52
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
John Joe
Ranch Hand
Posts: 570
3
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ?
 
Danny Alphones
Ranch Hand
Posts: 52
1
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.)  
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Note also that OP's program is extending this ConsoleProgram
 
Danny Alphones
Ranch Hand
Posts: 52
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yeah i found out that i could use a scanner if i wrote java.util.U*; instead of java.util.Scanner;
 
John Joe
Ranch Hand
Posts: 570
3
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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  
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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

Are you quite sure about that? Please check carefully.
 
Campbell Ritchie
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Campbell Ritchie
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
     
    Campbell Ritchie
    Marshal
    Posts: 79151
    377
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I merged your stuff with the following thread. I hope that is okay by you.
     
    Danny Alphones
    Ranch Hand
    Posts: 52
    1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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....

     
     
    Don't get me started about those stupid light bulbs.
    reply
      Bookmark Topic Watch Topic
    • New Topic