πŸ“˜ 221017 JAVA κ°œλ°œμΌμ§€ DAY+5

rossiebiΒ·2022λ…„ 10μ›” 17일
0

πŸ’» JAVA κ°œλ°œμΌμ§€Β 

λͺ©λ‘ 보기
8/38
post-thumbnail

πŸ”” [ λ°°μ—΄μ˜ ν™œμš©]

πŸ“Œ 예제 : λ°°μ—΄μ˜ λͺ¨λ“  μš”μ†Œλ₯Ό λ”ν•΄μ„œ 총합과 평균 κ΅¬ν•˜κΈ°

public class practice_10 {
	public static void main(String[] args) {
		int sum = 0; 
		float average = 0f;
		
		int [] score = {100, 88, 100, 100, 90};
		
		for(int i =0; i<score.length; i++) {
			sum += score[i];
		}
		average = sum/(float)score.length;
		System.out.println("총합 : " + sum);
		System.out.println("평균 : " + average);
		
	}

}

πŸ“Œ 예제 : λ°°μ—΄μ˜ μš”μ†Œ 쀑 제일 큰 κ°’κ³Ό 제일 μž‘μ€ 값을 μ°ΎκΈ°

public class practice_2 {
	public static void main(String[] args) {
		int [] score = {79, 88, 91, 33, 100, 55, 95};
		
		int max = score[0]; // λ°°μ—΄μ˜ 첫 번째 κ°’μœΌλ‘œ μ΅œλŒ€κ°’μ„ μ΄ˆκΈ°ν™”ν•œλ‹€. 
		int min = score[0]; // λ°°μ—΄μ˜ 첫 번째 κ°’μœΌλ‘œ μ΅œμ†Œκ°’μ„ μ΄ˆκΈ°ν™”ν•œλ‹€. 
		
		for(int i=1; i<score.length; i++) {
			if(score[i] > max) {
				max = score[i];
			}else if(score[i] < min) {
				min = score[i];
			}
		}
		System.out.println("μ΅œλŒ€κ°’: " +max);
		System.out.println("μ΅œμ†Œκ°’: " +min);
	}
}

πŸ“Œ 예제 : λ°°μ—΄μ˜ μš”μ†Œμ˜ μˆœμ„œλ₯Ό λ°˜λ³΅ν•΄μ„œ λ°”κΎΈκΈ° (숫자 μ„žκΈ°, 둜또번호 생성)

import java.util.Arrays;


public class practice_3 {
	public static void main(String[] args) {
		int [] numArr = {0,1,2,3,4,5,6,7,8,9};
		System.out.println(Arrays.toString(numArr));
		
		for(int i=0; i<100; i++) {
			int n= (int)(Math.random()*10);
			int tmp = numArr[0];
			numArr[0] = numArr[n];
			numArr[n]= tmp;
		}
		System.out.println(Arrays.toString(numArr));
	}
}

πŸ”” [ 2차원배열 ]

πŸ“’ 2차원배열 : ν…Œμ΄λΈ” ν˜•νƒœμ˜ 데이터λ₯Ό μ €μž₯ν•˜κΈ° μœ„ν•œ λ°°μ—΄

πŸ”” [ λ©”μ„œλ“œλž€? ]

πŸ“’ λ©”μ„œλ“œ : λ¬Έμž₯듀을 묢어놓은 것

  • μ½”λ“œμ˜ 쀑볡은 λ°˜λ“œμ‹œ μ œκ±°ν•΄μ•Όν•¨
  • μž‘μ—… λ‹¨μœ„λ‘œ λ¬Έμž₯듀을 λ¬Άμ–΄μ„œ 이름 뢙인 것

πŸ”” [ String 클래슀 ]

πŸ“’ - string ν΄λž˜μŠ€λŠ” char[]와 λ©”μ„œλ“œ(κΈ°λŠ₯)λ₯Ό κ²°ν•©ν•œ 것

	 - λ‚΄μš©μ„ λ³€κ²½ν•  수 μ—†λ‹€!
profile
λΉ„μ „κ³΅μž 개발자λ₯Ό κΏˆκΎΈλŠ” λ‘œμ§€

0개의 λŒ“κΈ€