File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Error in the Following Code. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Error in the Following Code." Watch "Error in the Following Code." New topic

Error in the Following Code.

Zeeshan Saleem

Joined: Mar 01, 2005
Posts: 2
class zee
public static void main (String args[])
short a = 10, b = 20 , c;
c = a + b;
System.out.println (c+" ");

Please Correct that Code.
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
Did you get a compiler error? If so, please post it so we can show you how to interpret the error message. This is a very important skill to learn early.
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
yup, there will be a compiler error.
There's of course also the glaring style error in the class name, not to mention the lack of a package (neither of them actually illegal but both bad practice).

John Dell'Oso
Ranch Hand

Joined: Apr 08, 2004
Posts: 130

As David has already pointed out, you should post the compiler error you are receiving. In addition to this, you also need to check out some Java coding conventions as suggested by Jeroen. Here are the recommended coding conventions from Sun's java website:

Code Conventions for the Java Programming Language

I don't agree 100% with ALL of the standards in this document, but most of it is applicable. I would start with Section 9 - Naming Conventions.

Now back to the problem with your code snippet - just a small hint that may assist in solving your issue - read up on Java numeric data types and how Java arithmetic works. Also check out the topic of casting.

Good luck!

Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

This thread apparently continues here.

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link:
subject: Error in the Following Code.
It's not a secret anymore!