Java परिचय
Jim White
Java Developer
वैरिएबल्स के साथ काम, बदलाव
ऑपरेटर्स: अलग-अलग काम के लिए बिल्ट-इन symbols
Arithmetic operators

public class Main {
public static void main(String[] args) {
// Assign calculation to variable a
int a = 5 + 6;
// Print the value of a
System.out.println(a);
}
}
11
// Adding doubles double x = 5.5; double y = 4; double xPlusY = x + y; // Value is 9.5// String concatenation String message = "Hello"; String messageForJim = message + " Jim"; // Value is "Hello Jim"
++ से वैल्यू 1 बढ़ाएँint age = 30;
// 1 जोड़ने के लिए increment
age++; // अब वैल्यू 31 है
// Subtract double productPrice = 99.9; productPrice = productPrice - 10; // अब वैल्यू 89.9 है// Decrement value int productLaunch = 99; productLaunch--; // अब वैल्यू 98 है
int price = 100; int quantity = 1; // दो integers का गुणन int orderRevenue = newPrice * quantity; // वैल्यू 100 है, intdouble newPrice = 94.9; int quantity = 1; // double के साथ गुणन double newOrderRevenue = newPrice * quantity; // वैल्यू 94.9 है, double
class IntDivision {
public static void main (String[] args){
int numOrders = 100;
int days = 30;
// आउटपुट 3 है,
// क्योंकि दोनों संख्या integers हैं
System.out.println(numOrders / days);
}
}
3
class DoubleDivision {
public static void main (String[] args){
int numOrders = 100;
int days = 30;
// Either assing to double
double avgOrders = numOrders / days;
System.out.println(avgOrders);
// Or use a double in the division
System.out.println(numOrders / 30.0);
}
}
3.3333333333333335
| ऑपरेशन | ऑपरेटर | उदाहरण |
|---|---|---|
| जोड़ | + |
5 + 1.5 |
| घटाव | - |
3.6 - 2 |
| गुणन | * |
0.3 * 2 |
| भाग | / |
59 / 4 |
int का भाग int देता है, जब तक double को असाइन न करेंdouble हो, तो परिणाम double होता हैJava परिचय