The Artima Developer Community
Sponsored Link

Java Answers Forum
New to Java?

1 reply on 1 page. Most recent reply: Dec 8, 2009 7:08 AM by Vincent O'Sullivan

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
midnight sun

Posts: 1
Nickname: midnightsu
Registered: Dec, 2009

New to Java? Posted: Dec 8, 2009 5:41 AM
Reply to this message Reply
Advertisement
Okay so i just started learning Java few days ago and right I am practising to write basic codes. I have just written the code below but when i try to compile it a error comes saying: 2 errors found. Can someone tell me how I can fix these errors:

class Numbers {
public static void main (Strings[] 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);
}
}
ty


Vincent O'Sullivan

Posts: 724
Nickname: vincent
Registered: Nov, 2002

Re: New to Java? Posted: Dec 8, 2009 7:08 AM
Reply to this message Reply
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.

Flat View: This topic has 1 reply on 1 page
Topic: Mortgage Homework Previous Topic   Next Topic Topic: help..

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use