Double ko integer me convert karke print karne ke liye aap int keyword ka upayog karte hain, jo ki "type casting" ya "explicit type conversion" kehte hain. Isse double value ko integer me convert kiya jaata hai. Aap yeh type casting kisi bhi of the following tarike se kar sakte hain:
Type Casting Using (int):
javadouble doubleValue = 10.5; int intValue = (int) doubleValue; System.out.println(intValue);
Aapne do alag-alag tarike se values ko print karne ke liye if aur else if statements ka upayog kiya hai:
Using Integer Literal (Without Quotes):
javaelse if (ch == 'X') { System.out.print(10); } else if (ch == 'L') { System.out.print(50); } else if (ch == 'C') { System.out.print(100); }Using String Literal (With Quotes):
javaelse if (ch == 'X') { System.out.print("10"); } else if (ch == 'L') { System.out.print("50"); } else if (ch == 'C') { System.out.print("100"); }
In dono tarike mein if aur else if statements ke block me condition check kiya ja raha hai, aur jab shart puri hoti hai, tab uske associated value print kiya jata hai.
Difference:
- Pehla tareeka integer literals (bina double quotes ke) ko print karta hai, jisse aapke output me direct integer ki value print hoti hai.
- Dusra tareeka string literals (double quotes ke saath) ko print karta hai, jisse output string ki tarah dikhayi dega.
Agar aap pehle tareeke ko istemal karte hain (integer literals), toh aap direct integer ki value ko print karenge. Lekin agar aap doosre tareeke ko istemal karte hain (string literals), toh aap string ko print kar rahe hain jisse double quotes ke bina hi value display hoti hai.
- Integer print krne ke liye hamen kisi bhi quotes ki jarurt nhi hoti
- Double quote agr ham lgate hai to usse ham ye samjh skte hai ki ham ek string
- single character hai to single quote
Comments
Post a Comment