Search code examples
javatypesidentifierprimitive-types

Determine the data types


I'm very new to programming and still getting confused with some things. Below is a class exercise.

We have to use the context in the below code to determine the data type of the identifiers in the code.

if (a.length( ) > 10)

{

     b = ! ( c < 4 );

     z = ugly ( a, b, c – 9 );

}

if ( z.equals( “I think I got it” ) )

{

     System.out.println ( “Yea” );

}

Here were my answers: a; is int

b; is int

c; is int

z; is String

I'm sure I got a few wrong. I guess I get confused when I see 'a' & 'z' in multiple places. Again, I'm just trying to get a better understanding at identifying them.


Solution

  • a.length()
    

    length() is a method of the String object;

    c < 4 
    

    This is boolean test (result can be true or false) where c can be number (int).

    z.equals( “I think I got it” )
    

    equals is a method of Object, but it checks z value in this case with String.

    So a is String

    b is boolean

    c is int or other numeric (maybe long or byte, short)

    z is String or otehr non-primitive Object