• 0

Beginning Java Program


Question

So this is a long shot but I've been part of neowin for a while and think you folks might be able to help me. I am in my first java program design class in college and need to a program that will

"Write a Java program that accepts numeric input from the user (integer value)

2. Print out the square and cube of the number entered.

3. Make sure that the number is > 0.

4. Repeat the above three times.

5. If the number entered is <= 0 then end the program, telling the user why.

Include appropriate prompts so that the user knows what to do."

I have no clue where to start, I have looked recently at other forums here and wow this is like spanish to me, maybe because I'm just starting, just looking for some help if anyone has any to offer.

Thank you!

Link to comment
https://www.neowin.net/forum/topic/1057452-beginning-java-program/
Share on other sites

7 answers to this question

Recommended Posts

  • 0

Can you write and run any Java program at all? Do you have a development environment set up, such as Eclipse or Netbeans? Are you on Windows, Mac, Linux? Do you know how to print something to the console? Don't your class recommend a textbook or other resources? This sort of stuff is explained in detail in dozens of books and tutorials if you just take a look.

  • 0

1. Use scanner to read input: http://docs.oracle.c...il/Scanner.html The first example in that doc is what you'll need.

2. http://docs.oracle.c...dbolts/op1.html (multiplication operator) or for a more advanced case Math.pow (http://docs.oracle.com/javase/6/docs/api/java/lang/Math.html#pow(double, double))

3. http://docs.oracle.c...dbolts/op2.html

4. http://docs.oracle.c...olts/while.html or http://docs.oracle.c...dbolts/for.html

5. See 3 and 6 to learn how to do this.

6. Use Console (http://docs.oracle.c...io/Console.html) or System.out (http://docs.oracle.c...ang/System.html and http://docs.oracle.c...rintStream.html) to print prompts out to the user.

Hopefully that should give you some hints and good sources of documentation for you to learn about the Java language. I'll leave it to you to put the pieces together.

  • 0

the program you are asking info on how to right is very simple ..

I will not give it to you but I shall, help you with one or two bits of code you need...

obviously you need a JDK to even get started... i recommend eclipse...

This will allow input from a command line nothing graphical.


Scanner action = new Scanner(System.in);
System.out.println("enter a number");
input = action.nextLine();
[/CODE]

in all honesty this is all im going to give you... everything else is very simple and if this is for your class then I am not helping you by giving you the answers :) im sure you know how to do IF else statements and for loops

  • 0

I can't recommend Head First Java enough for beginners. I read the book a few weeks ago as a refresher since I hadn't done any Java programming since college. The book's cover makes it look stupid so I never thought twice about it. However, I just decided to go for it after reading some reviews, and it seriously was a fantastic read for people new to the language. I really recommend it.

I know it's not a direct answer to the OP's problem, but the book will really give you the tools to solve this problem as well as future ones.

http://www.amazon.com/Head-First-Java-Kathy-Sierra/dp/0596009208/ref=sr_1_1?ie=UTF8&qid=1328983484&sr=8-1

This topic is now closed to further replies.
  • Posts

    • I'd say the first one failed to be as popular as Apple anticipated, but the easy adjustment here is to make fewer of them next time around. It would only be a "flop" if it isn't possible for Apple to recover the design and factory tooling costs given the number of units sold, which I doubt would be the case. It isn't like no one bought them; it just failed to become the new hot phone of the year.
    • You're right that it does not follow the plain meaning of the word, but in this context, it is a legal term defined in 49 U.S.C. Kind of how "wire fraud" laws apply even if a physical wire was not used. Given that it is codified in law, and it isn't just automotive journalists that don't understand evolving technology, I highly doubt congress would change a well understood term just because technology makes the term slightly less actuate.
    • This is exactly why I keep saying we are not ready for human free self-driving. These little "bugs" are may seem like random one-offs. There was also the Waymo that drove between police with drawn weapons and the suspect they were pointing them at. From a software perspective it is easy to understand how those extremely rare situations may not have been programed for, but that is the point. If AI needs to be told to watch out for every possible contingency, then it can never be successful. There will always be the possibility of a first encounter that the AI needs to understand to avoid.
    • TeraCopy 4.0 Final by Razvan Serea TeraCopy is a compact program designed to copy and move files at the maximum possible speed, also providing you with a lot of features. Copy files faster. TeraCopy uses dynamically adjusted buffers to reduce seek times. Asynchronous copy speeds up file transfer between two physical hard drives. Pause and resume transfers. Pause copy process at any time to free up system resources and continue with a single click. Error recovery. In case of copy error, TeraCopy will try several times and in the worse case just skips the file, not terminating the entire transfer. Interactive file list. TeraCopy shows failed file transfers and lets you fix the problem and recopy only problem files. Shell integration. TeraCopy can completely replace Explorer copy and move functions, allowing you work with files as usual. TeraCopy is free for non-commercial use only. For commercial use you need to buy a license. The paid version of the program includes the following features: Copy/move to your favorite folders. Save reports as HTML and CSV files. Select files with the same extension/folder. Remove the selected files from the copy queue. Download: TeraCopy 4.0 | 14.6MB (Freeware, paid upgrade available) View: TeraCopy Website | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
  • Recent Achievements

    • Week One Done
      Eurosoft10 earned a badge
      Week One Done
    • One Month Later
      Eurosoft10 earned a badge
      One Month Later
    • One Year In
      Skeet Campbell earned a badge
      One Year In
    • One Month Later
      Sharbel earned a badge
      One Month Later
    • First Post
      BizSAR earned a badge
      First Post
  • Popular Contributors

    1. 1
      +primortal
      586
    2. 2
      +Edouard
      187
    3. 3
      Michael Scrip
      74
    4. 4
      PsYcHoKiLLa
      72
    5. 5
      neufuse
      69
  • Tell a friend

    Love Neowin? Tell a friend!