Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 |
Tags
- 사전학습
- Position
- 예제
- CSS
- GridLayout
- html 프로젝트
- 퍼셉트론
- Database
- 파이썬
- 푸리에 변환
- 메서드
- iframe 태그
- oracle
- 반응형웹
- 미디어쿼리
- 상속
- ObjectOutputStream
- 반응형 웹 프로젝트
- BorderLayout
- HTML
- inline
- css 기초
- FileWriter
- java
- html 기초
- FFT
- FlowLayout
- Codility
- rnn
- g검정
Archives
- Today
- Total
도라에몽주머니
[Java/Eclipse] Java 13일차 본문

예제
학생 5명의 성적을 입력한 후, 총점과 평균을 구해보자.
Class name: Prac1.java
<실행 결과>
1번 학생의 점수를 입력 : 79
2번 학생의 점수를 입력 : 74
3번 학생의 점수를 입력 : 89
4번 학생의 점수를 입력 : 85
5번 학생의 점수를 입력 : 97
총점 : 424, 평균 : 84.8
import java.util.Scanner;
public class Prac1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[] score = new int[5];
int total=0;
for(int i=0; i<score.length; i++) {
System.out.print((i+1) + "번 학생의 점수를 입력 : ");
score[i] = sc.nextInt();
total += score[i];
}
System.out.println();
System.out.println("총점 : " + total + ", 평균 : " + (double)total/score.length);
}
}
예제
1월 1일부터 입력한 날까지 일수를 구해보자
Class name: Prac2.java
<실행 결과>
*** 일수 구하기 ***
월 : 5
일 : 5
1월1일부터 5월5일까지는 125일 입니다.
import java.util.Scanner;
public class Prac2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[] months = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int month = 0;
int day = 0;
int total = 0;
System.out.println("*** 일수 구하기 ***");
System.out.print("월 : ");
month = sc.nextInt();
System.out.print("일 : ");
day = sc.nextInt();
for(int i=0; i<month-1; i++) {
total += months[i];
}
total += day;
System.out.println("\n1월1일부터 " + month + "월" + day + "일까지는 " + total + "일 입니다.");
}
}'Study > Java' 카테고리의 다른 글
| [Java/Eclipse] Java 15, 16일차 (0) | 2022.10.06 |
|---|---|
| [Java/Eclipse] Java 14일차 (1) | 2022.10.04 |
| [Java/Eclipse] Java 12일차 (0) | 2022.09.29 |
| [Java/Eclipse] Java 11일차 (0) | 2022.09.28 |
| [Java/Eclipse] Java 10일차 (0) | 2022.09.27 |