Variable Statement Syntax
Variable Statement Syntax
Syntax:
Variable=expression;
Semantics:
1)Evaluate the expression
2)Copy the result from step 1 into the variable
To copy a value into a variable you place that value
system.out.point(“X=”+X)
Operator overloading: an operator (for example a plus sign) can be used for more than 1 thing.
Here the + sign means concatenation
Concatenation is an operation that combines two single strings composed of characters from
the original two strings in the same order that they occur in the original two strings.
Ex: “Hi”+”There”
Hi there”
The objects in which an operator is applied are generically called operants
5+3
5 and 3 are the operants
If either of the two operands of a concatenation is a string then Java automatically treats both
operands as strings.
Memory
x
8
int
system.out.print(What is your name?); (Nikita)
String name;
name=keyboard.next();
System.out.print(“Nice to meet you”+name) (Nikita)
Code:
system.out.print(What is your name?);
String name;
name=keyboard.next();
System.out.print(“Nice to meet you”+name)
Screen
What is your name?_
Memory
name
string
Variable
=
Expression
;
Screen
What is your name? Nikita
Memory
name
Nikita
string
Screen
What is your name? Nikita
Nice to meet you Nikita
Memory
name
Nikita
string
Memory
x
Int
Screen
Enter a number ->5
Memory
x
Int
Screen
Enter a number ->5
Enter another ->
Memory
x
5
Int
Screen
Enter a number ->5
Enter another ->3
Memory
x
5
Int
int
Screen
Enter a number ->5
Enter another ->3
Memory
x
5
Int
3
Int
Int
Screen
Enter a number ->5
Enter another ->3
X+Y=8
5+3=8
Memory
x
5
Int
3
Int
z
8
Int
Screen
Memory