• Post Reply Bookmark Topic Watch Topic
  • New Topic

Check my Java coding.  RSS feed

 
Joshua Soppe
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's been two years since I've done any java programming. I'm supposed to start back up with this basic math program that seems to have just one problem now that keeps it from compiling. Could you point it out to me? Thank you!

 
Ove Lindström
Ranch Hand
Posts: 326
Android Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can't your compiler help you with that?

A actually don't get any compiler warnings when trying out this class.

Is the name of the file that contains this class mathOperation.java? (Should actually be MathOperation in both file name and type declaration).
 
Joshua Soppe
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The name of the file is the same as the class, so that should not be the problem.

My compiler through Textpad just says "Tool completed successfully". Heck no it didn't. Doesn't even show the first line of print. The eclipse software tells me "The selection cannot be launched, and there are no recent launches."

So then I tried browxy.com which is an online java compiler that gave me this:
--- Starting Compilation ---

--- Finished Compilation succesfully ---

--- Starting Execution ---

Enter first whole number: Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:838)
at java.util.Scanner.next(Scanner.java:1461)
at java.util.Scanner.nextInt(Scanner.java:2091)
at java.util.Scanner.nextInt(Scanner.java:2050)
at SummerOne.main(SummerOne.java:9)

--- Finished Execution Normally ---
(The class and the file name at the time was SummerOne)

I don't quite understand what this means.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
look and see if you got a .class file. That will tell you if it compiled successfully or not. Of course, I compile from the command line, which also would let you know if it compiled correctly or not.

I also run it from the command line, and it worked as-is:


C:\slop>javac mathOperation.java

C:\slop>java mathOperation
Enter first whole number: 2
Enter second whole number: 2

2 + 2 = 4
2 - 2 = 0
2 * 2 = 4
2 / 2 = 1 with a remainder of 0

Enter first decimal number: 6
Enter second decimal number: 8

6.0 + 8.0 = 14.0
6.0 - 8.0 = -2.0
6.0 * 8.0 = 48.0
6.0 / 8.0 = 0.75 with a remainder of 6.0

Thank you for running my math program!!
C:\slop>



Note that I think your division of floats is wrong...6.0 divided by 8.0 is 0.75, with no remainder.
 
Ove Lindström
Ranch Hand
Posts: 326
Android Firefox Browser Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Compiling (javac) and running (java) is not exactly the same thing.
 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Too much code in the main method.
No objects created in that application.
 
Joshua Soppe
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Fred! Looks like the code is fine, there's just something wrong with how I set up my compiling stuff. I did find that .class file right next to the .java file, too.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!