반응형

전체 글 1141

4장 확인문제 4번 주사위 합 while문 이용

package ch4; public class Exercise04 { public static void main(String[] args) { // while문과 Math.random() 메소드를 이용해서 두 개의 주사위를 던졌을 때 나오는 눈을 // (눈1, 눈2) 형태로 출력하고, 눈의 합이 5가 아니면 계속 주사위를 던지고, 눈의 합이 5이면 실행을 멈추는 코드를 작성해보세요. // 눈의 합이 5가 되는 조합은 (1,4), (4, 1), (2, 3), (3,2) 입니다. boolean run = true; for(int i = 0; i

6장 확인문제 19번 ** Getter, Setter 기본 문제

package Chapter6; public class Account { private final static int MIN_BALANCE = 0; private final static int MAX_BALANCE = 1000000; private int balance; //balance를 받을 getter 생성 public int getBalance() { return balance; } public void setBalance(int balance) { if(balance > MAX_BALANCE || balance < MIN_BALANCE) { return; } else { this.balance = balance; } } } package Chapter6; public class AccountEx..

5장 확인문제 9번

출력결과 import java.util.Scanner; public class StudentSystem { public static void main(String[] args) { boolean run = true; int studentNum = 0; int[] scores = null; Scanner scn = new Scanner(System.in); int max = 0; int sum = 0; // 그냥 int sum; 하고 선언해주면 값 0으로 초기화 되는 것이 아닌가? while(run) { System.out.println("------------------------------------"); System.out.println("1.학생수 2.점수입력 3.점수리스트 4.분석 5.종료"); ..

5장 확인문제 8번

public class Array { public static void main(String[] args) { //주어진 배열의 전체 항목의 합과 평균값을 구해보세요(중첩 for문을 이요하세요.) int[][] array = { {95, 86}, {83, 92, 96}, {78, 83, 93, 87, 88} }; int sum = 0; int count = 0; for(int i = 0; i < array.length; i++) { for(int k = 0; k < array[i].length; k++) { sum += array[i][k]; count++; } } double avg = (double)sum/count; System.out.println("합 : " + sum); System.out.p..

이것이 자바다 5.63 참조타입 배열 평균 구하기 예제

public class Array { public static void main(String[] args) { int [] scores; scores = new int[] {12, 23, 45}; System.out.println("scores[0] : " + scores[0]); System.out.println("scores[0] : " + scores[1]); System.out.println("scores[0] : " + scores[2]); int sum = 0; for(int i = 0; i < 3; i++) { sum += scores[i]; } double avr = (double)sum/3; System.out.println("scores[0]scores[1]scores[2]의 합 : "..

카테고리 없음 2020.10.08
반응형