전체 글155 Day 13. Q. 코드 작성!! > 학생 관리 class Student { int id; String name; int LanguageScore; int EnglishScore; int MathScore; double average() { return ((LanguageScore + EnglishScore + MathScore) / 3.0 * 100) / 100; } int TotalScore() { return LanguageScore + EnglishScore + MathScore; } } package chap06; import java.util.*; public class StudentEx { public static void main(String[] args) { Scanner sc = new Scanner.. 2022. 1. 18. Day 12-3. Q. 선택정렬 import java.util.Arrays; public class SelectArray { public static void main(String[] args) { int[] arr = {40, 50, 30, 10, 20}; int tmp = 0; for(int i = 0; i arr[j]) { tmp = arr[i]; arr[i] = arr[j]; arr[j] = tmp; } } System.out.println(Arrays.toString(arr)); } } } 2022. 1. 18. Day 12-2. Q. 삽입정렬 import java.util.Arrays; public class InsertArray { public static void main(String[] args) { int[] arr = {40, 50, 30, 10, 20}; for(int i = 1; i = 0; j--) { // 선택 정렬 if(arr[j] > arr[idx]) { int tmp = arr[j]; arr[j] = arr[idx]; arr[idx] = tmp; } else break; idx--; System.out.println(Arrays.toString(arr)); } } } } 2022. 1. 18. Day 12-1. 버블 정렬 public class ArrayEx10 { public static void main(String[] args) { int[] numArr = new int[5]; for(int i = 0; i numArr[j+1]) { // 옆의 값이 작으면 서로 바꾼다. int temp = numArr[j]; numArr[j] = numArr[j+1]; numArr[j+1] = temp; changed = true; } } if(!changed) break; for(int k = 0; k < numArr.length; k++) { System.out.print(numArr[k]); } System.out.println(); } } } 2022. 1. 16. 이전 1 ··· 31 32 33 34 35 36 37 ··· 39 다음