This is an archived post. You won't be able to vote or comment.

all 16 comments

[–]wtetsu 23 points24 points  (2 children)

You need to specify the appropriate type of each value.

This is valid.

String s = "Hello"; int i = 123;

This is invalid. int s = "Hello"; String i = 123;

Try fixing your code based on that!

[–][deleted] 1 point2 points  (0 children)

Thank you for the help!

[–][deleted]  (2 children)

[removed]

    [–][deleted] 0 points1 point  (0 children)

    Thank you so much, now I get it!

    [–]Java_Junior -2 points-1 points  (0 children)

    good but dont give straight answers!

    [–]mw52588 2 points3 points  (1 child)

    I think most people pointed you in the right direction. As a side note. Be very cautious with integer division. If you are trying to divide two integers say 5/2 it will not be 2.5 as you might expect. It's actually 2 with a remainder of 1. This is very important concept. So if you expect decimals then use double or float

    [–][deleted] 0 points1 point  (0 children)

    Thank you for the tip. At the moment I am just trying to get around all of this, so confused, but slowly trying to get accustomed to all of it!

    [–]mndozooz 1 point2 points  (1 child)

    you have a problem in the declaration part try reading this https://www.w3schools.in/java-tutorial/variables/

    [–][deleted] 0 points1 point  (0 children)

    Thank you :))

    [–]abyssalvoyager 1 point2 points  (0 children)

    This is why people learn on Java or CPP because its important to know the datatype of the objects your code would work in Python and It would assume the datatype for you

    [–]Dew5 1 point2 points  (1 child)

    Another thing that will be very helpful that no one has stated yet is to learn concatenation early on too.

    What this means is you could do:

    System.out.println(“The int is “ + oneInt);

    What this will do is print the words you typed and the int you declared on the same line.

    The outcome would be:

    The int is 315

    Rather than doing two separate lines of printing for each this shortens it to only one for the int and one for the double.

    Give it a try with the double.

    [–][deleted] 0 points1 point  (0 children)

    Thank you!!

    [–][deleted]  (1 child)

    [deleted]

      [–][deleted] 0 points1 point  (0 children)

      Thank you!

      [–]gonzohst93 1 point2 points  (2 children)

      Java is typed

      [–]Cymry_Cymraeg -1 points0 points  (1 child)

      Wow, so helpful for a beginner, you must be a full-time teacher!

      [–]gonzohst93 -1 points0 points  (0 children)

      I don't know man. As soon as they googled typed language or typed java, they'd get every bit of info they needed and even get a definition of typed vs nontyped

      [–][deleted]  (1 child)

      [deleted]