Random2 이것이 자바다 - 챕터4 연습 문제 3번 // 3번 int sum = 0; for(int i =1;i4번 // 4번 while(true) { int one = (int)(Math.random() * 6 + 1); int two = (int)(Math.random() * 6 + 1); System.out.println("1 번째 : " + one); System.out.println("2 번째 : " + two); if(one + two == 5) { System.out.println("주사위 합 : " + (one + two)); break; } } 5번// 5번 for(int i = 0; i6번// 6번 for(int i=0;i7번// 7번 int money = 0; .. 2025. 4. 5. 4/3 - 변수, 조건문, 반복문 변수 초기화변수는 초기화하지 않아도 사용하지 않으면 에러는 나지 않음Object모든 타입 수용 가능모든 타입으로 형 변환 가능연산대입 연산복합 대입 연산피 연산자 연산자= 피 연산자ex) 1 += 2연산을 한 후의 값을 반영산술 연산컴퓨터는 소수점 연산을 기본적으로 못하므로 실수 연산의 경우 오차가 발생할 수 있음정수로 바꿔서 계산하고 (10 단위로 곱셈) 다시 나누는 방식으로 계산0으로 나눌 경우 예외 발생package ch03;public class Operate { public static void main(String[] args) { int score1 = 90; int score2 = 80; int score3 = 75; int total = score1 + score2 + score3.. 2025. 4. 5. 이전 1 다음 728x90 반응형