Hey! I just started in here .. am kinda confused can someone please help me with variables! ... it's java lesson 5 I think ...variables... thnk U


#1

<You can use the questions listed here: About the Stories & Projects category to help write your story.>


#2

Without code, a link to the lesson, or an error message, there’s not a ton we can do to help you

However, a bit of advice for variables in java:
unlike languages such as Python or JavaScript, you have to specify the data type before the variable name
so simply writing x = 12 you have to specify x as a data type capable of handling numbers, such as an integer, or a float
for example:
int x = 12 will make the x variable equal to a 32-bit signed integer
there are other data types such as

  • Bool: A boolean value that is either true or false
  • Float A single-precision 32-bit IEEE 754 floating point (it can handle decimals, basically)
    There are other data types, which you can find more information about here

#3

Thnk u…
Sorry my English is kinda bad!

The problem is this

           int myNumber;
	boolean isFun; 
	char movieRating; 

I don’t know What to right
I’m new so I don’t know a lot
Can u help me


#4

When you’re creating a variable, you can choose to assign it a value:

for example, when you type int myNumber = 4, it creates a variable called myNumber which can then be used multiple times later on in your code.

you have to use the = sign to actually give your variable a value though, otherwise it’s just null


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.