Java Basics (Variables and dataTypes)
Boiler code:-
Output in java:-
print function hai yhn.
If we want to print a no. in this then
Output :- 1,2,3,4,5.
If baar baar print krna hai koi cheej .
Output:- 3 times “Hello World” print
Q) Sum of a and b .
Output:- sum of two numbers.
Q) print pattern
Type conversion and Type casting.
Isme ek type ke data ko dusre type me convert krte.
Type conversion wo conversion hota hai jo java apne je krke deta eg.
Byte-> short->int ->float->long->double
But reverse nhi krte java iskke liye humme forcefully krna hota hai.
Isme integer ko long me store kr skte lekin long ko interger me nhi because
long size me bara hota hai integer se.
Time compatible means dono no. he hai
Destination type> source type
isme source int a hai and destination
long b
But ye possible nhi hai
Q) Product of a and b.
Comment in java:-
// or /* */
Type Promotion in Expression:-
Examples on first :-
Note:-Type promotion kewal expression pe hota hai single variable pe nhi
Hum yhn data int se char me store kr rhe hai iisi liye nhi horha hai isme a-b int
hai aur c char hai .
Example:-
Yhn koi int nhi hai but ye aarha ki int se byte me convert nhi kr skte kynki
short,byte and char ko int me convert kr diya hai. Aagar lossy conversion krna
chahte to isme type cast kr denge hojayega.
Example on 2nd :-
Isme long , float ya double ko long, float and double me daal dega jiska size
sbse bara hoga usi hisab se
isme sbse bara double hai to double me sb change ho jayega.
Isme agar int bana de ans part me to error aa jayega
Note:- agar khud se type cast krwa rhe to dono me bracket lga ke
krna
Data Type in Java:-
Variables in java:-
a and b dono yhn pe identifier hai.
Hummese right to left lena ye sb question me eg: int a= 10; int b=5; a=b; isme b ki value a me assign
hogi new value a=b=5 hogyi hai
Q) calculate area of a circle
Practice Problems on this concepts;-
Solutions
Q1)
Q2)
Q3)
Q5) dollar bhi shi hai hoga ye .