0% found this document useful (0 votes)
74 views12 pages

Variable Statement Syntax

1) A variable statement assigns a value to a variable using the syntax "Variable=expression;". 2) When an expression is evaluated, its result is copied into the variable. 3) Operator overloading allows operators like "+" to perform different operations like concatenation of strings. Concatenation combines two strings into one by appending them in order.

Uploaded by

Nikita Shadurski
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views12 pages

Variable Statement Syntax

1) A variable statement assigns a value to a variable using the syntax "Variable=expression;". 2) When an expression is evaluated, its result is copied into the variable. 3) Operator overloading allows operators like "+" to perform different operations like concatenation of strings. Concatenation combines two strings into one by appending them in order.

Uploaded by

Nikita Shadurski
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Variable statement

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

String is a data type:

Data type variable


;

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

System.out.print(“Enter a number ->”)


Int x;
x+keyboard.nextInt(); [(5)(x=5)]
keyboard.next[Int]() Wait for user to type something in
System.out.print(“Enter another->”); [(3)(y=3)]
Int y;
y+keyboard.nextInt();
Int z;
Z(8)=x(5)+y(5);
system.out.print(“X+Y=”+Z);
Screen
Enter a number ->_

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

You might also like