lasasdf.blogg.se

Programers greek question mark
Programers greek question mark












programers greek question mark

Java does allow us to shorten variable declaration and initialization up a bit, syntactically. We call it the "assignment operator" instead, or "gets" for short.Īs "The variable myLuckyNumber gets the value 13."Ī Useful Shortcut - Variable Declaration and Assignment in One Statement In fact, we don't even call this symbol "equals". Note the equals sign here means something different than it does in mathematics. MyLetter = 'a' //Assigns the variable myLetter the MyLuckyNumber = 5+8 //Also assigns the variable myLuckyNumber MyLuckyNumber = 13 //Assigns the variable myLuckyNumber To assign a variable a value, we use the following syntax: Declare this variable of this type (that is to say: tell the computer to allocate an appropriate amount of memory for the type of variable given and reference that portion of memory by the name given), and that's it. It tells the computer that the statement of what to do is complete at this point. The semicolon on the end functions much like a period does in the English language. Int myLuckyNumber //Declares myLuckyNumber to be an integer variableĬhar myLetter //Declares myLetter to be a character variable Let's take a look at the syntax for declaring a variable:

#Programers greek question mark code#

When the code is written in a way the computer cannot understand, we say there is a syntax error. When code is written in a way that the computer can understand, we say the code is syntactically correct. Programming languages have a particular format you have to stick to when telling the computer what to do. They can't "read between the lines" or "figure out what you really meant". Of course, computers are picky about how you tell them to do something. When we assign a variable a value for the first time, we are said to be initializing the variable. Then we can assign a value to the variable - that is, tell it what to remember. Whenever we use a variable in a Java program, we must first declare the variable - that is, we specify what the type and name of the variable will be. We'll talk more about the differences between these in a little bit.Īlso, every variable has a name that refers to the location of that particular portion of memory (so the computer can find it again).Īnd of course, the value of a variable consists of whatever information currently occupies the memory referenced by its name. The first 6 allow for storage of different kinds of numbers, the last stores a single character (think "keyboard" character). These include: int, byte, short, long, float, double, boolean, and char. There are 8 primitive types of data built into the Java language. The amount of memory allocated for a given variable and how the value of that variable should be stored in memory depends upon its type. A variable in Java gives us a way to store values (or other kinds of information) for later use, addressing all of the aforementioned considerations. The concept of a variable solves all of our problems here. The computer also needs to have some reference to where it stored the value, so it can find it again.

programers greek question mark

Examples of types of encodings used include Two's Complement, IEEE 754 Form, ASCII, Unicode, etc. Further, we also need to tell the computer how the value should be stored in memory (i.e., what method of "encoding" should be employed to turn the value into a string of 1's and 0's). For example, it will certainly take more memory to store the Declaration of Independence than it will to store a single letter (i.e., a "character"). These things too, come in different sizes. Of course, we sometimes need to store things other than numbers. Different kinds of numbers require different amounts of memory (more on this in a minute). We need to tell the computer how much memory will be needed to store the value in question. Looking at step 1 in the program above, we will need to tell the computer that it needs to remember the value it is reading in - it needs to store this value in its memory somewhere so we can use it in a computation later. Remember: a computer will read and act upon these instructions one at a time - it is not aware of what is coming up until it gets there! Print the area to the standard output stream (i.e., the console window) Read a value representing the radius of a circle from the standard input source/streamĬompute the area of a circle with this radius You can think of a simple program as a list of instructions to be read and acted upon sequentially

programers greek question mark

The Purpose of a Variable (and some vocabulary)














Programers greek question mark