Suppose that you want to calculate something. First you must set up variables. Variables are things that stores values. For storing strictly numbers, use int (for whole numbers) or double (for numbers that have a dot like 5.12345). For words or a combination of words or numbers, use String:
The way you declare variables is this:
public class MyClass
{
public static void main(String[] args)
{
int a = 10;
int b = 25;
String name = "Yahoo12345";
}
}
Note: You must use semi colon after each statement of your code and you must put double quotes for the value of a String variable. To do a quick arithmetic on our two ints, set up a new variable like int answer = 0; Note: If you are setting up a placeholder like the "answer" int variable, set up the initial value of it to zero.
Now type "answer = a + b;" and "System.out.println("My answer is " + answer);". Your code should now look like this:
public class MyClass
{
public static void main(String[] args)
{
int a = 10;
int b = 25;
String name = "Yahoo12345";
int answer = 0;
answer = a + b;
System.out.println("My answer is " + answer);
}
}
After you compile it and run it, you should now see a new window that displays "My answer is 35".