|
|
Re: New to Java?
|
Posted: Dec 8, 2009 7:08 AM
|
|
There's a lot more than two errors in there but it's a good start.
- Java is (unfortunately) case sensitive. Almost every capital letter in your code should be lower case. Variable names (a, b, c, etc.) can be upper case but (by convention) always start with a lower case letter.
- The exception to the above is class names which (by convention) always start with a capital. Hence "String" (not "Strings"), Number and System in the code below.
- Finally, the syntax on the first "if" starement was wrong.
class Number
{
public static void main (String[] args)
{
int a = 5;
int b = 3;
int c;
if (a>b)
c = a/b;
if (a<b)
c = a*b;
System.out.println (c);
}
}
The solution below is similar but it prevents c having no value if a = b:class Number
{
public static void main (String[] args)
{
int a = 5;
int b = 3;
int c;
if (a > b)
c = a/b;
else
c = a*b;
System.out.println (c);
}
}
Hope that helps.
|
|