Java 소개
Jim White
Java Developer
변수로 작업하고 수정하기
연산자: 다양한 작업을 위한 내장 기호
산술 연산자

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 증가시키기
age++; // 이제 31
// Subtract double productPrice = 99.9; productPrice = productPrice - 10; // Value is now 89.9// Decrement value int productLaunch = 99; productLaunch--; // Values is now 98
int price = 100; int quantity = 1; // Multiply two integers int orderRevenue = newPrice * quantity; // Value is 100, intdouble newPrice = 94.9; int quantity = 1; // Multiply with double double newOrderRevenue = newPrice * quantity; // Value is 94.9, double
class IntDivision {
public static void main (String[] args){
int numOrders = 100;
int days = 30;
// Output is 3,
// because both numbers are 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
| Operation | Operator | Example |
|---|---|---|
| Addition | + |
5 + 1.5 |
| Subtraction | - |
3.6 - 2 |
| Multiplication | * |
0.3 * 2 |
| Division | / |
59 / 4 |
int의 나눗셈은 double에 할당하지 않으면 int를 반환double이면 결과는 doubleJava 소개