Jump to content

Java Incompatible Type Error

- - - - -

  • Please log in to reply
2 replies to this topic

#1
Pwincy Priya

Pwincy Priya

    Newbie

  • Members
  • PipPip
  • 22 posts
Currently i am facing a problem showing incompatible type error for my source code and i could not recognize where exactly the problem is. Can any help me out. Here is my source code:
public class String {

    public static void main(String args[]) {

        String str;
        int num1, num2;

        num1 = 12;
        num2 = 26;

        str = "The sum = " + num1 + num2;
        System.out.println("Line 4: str: " + str);

        str = "The sum = " + (num1 + num2);
        System.out.println("Line 6: str: " + str);

        str = num1 + num2 + " is the sum";
        System.out.println("Line 8: str: " + str);

        str = "The sum of " + num1 + "and" + num2 + "=" + (num1 + num2);
        System.out.println("Line 10: str: " + str);

    }

}
Thanks.

Edited by Alexander, 17 November 2010 - 03:03 AM.
Added [code] tags


#2
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
Try to not name your class String.

----------------------------------------

Or change String str;
into

java.lang.String str;

Same with the string[] args:

java.lang.String[] args



#3
Pwincy Priya

Pwincy Priya

    Newbie

  • Members
  • PipPip
  • 22 posts
Thank you.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users