#12 #자바여름방학과제

서영·2025년 7월 25일
3

JAVA

목록 보기
6/6
post-thumbnail

1.실수를 반복해서 입력받아 합과 평균을 출력하는 프로그램

파일명: Accumulate_학번_제출날짜.java

조건

  • do~while문을 사용하여 숫자를 반복해서 입력받고
  • 0을 입력받으면 반복을 중단하고 합을 출력한다.
  • 평균은 소수 아래 5자리까지 구한다.

<<출력 결과>>
1번째 숫자를 입력하세요 : 3.25
2번째 숫자를 입력하세요 : 2.48
3번째 숫자를 입력하세요 : 6.77
4번째 숫자를 입력하세요 : 9.1
5번째 숫자를 입력하세요 : 0.45
6번째 숫자를 입력하세요 : 1.96
7번째 숫자를 입력하세요 : 0
입력한 숫자의 합은 24.01입니다.
입력한 숫자의 평균은 4.00167입니다.

정답코드

import java.util.Scanner;
//1208_이서영
public class Accumulate_1208_0723 {
    public static void main(String[] args) {
        Scanner scan =  new Scanner(System.in);
        int num = 1;
        double scannum =0;
        double sum = 0;
        double avg = 0;

        do{
            System.out.print(num+"번째 숫자를 입력하세요 : ");
            scannum = scan.nextDouble();
            num+=1;
            sum+=scannum;
        }
        while (scannum>0);

        System.out.println("입력한 숫자의 합은 "+sum+"입니다.");
        System.out.print("입력한 숫자의 평균은 ");
        System.out.printf("%.5f",(sum/(num-2)));
        System.out.print("입니다.");
    }
}

2. 출석률을 확인하는 프로그램

파일명: Attendance_학번_제출날짜.java

조건

  • 출석 데이터로 1은 출석, 0은 결석을 의미함
  • 출석 데이터를 저장할 2차원 배열을 생성해서 출력

<<출력 결과>>
학생 수 입력 : 5

<<지난 주 출석 데이타>>
학생 1 : 1 1 1 1 1
학생 2 : 1 0 1 1 1
학생 3 : 1 0 1 0 1
학생 4 : 0 1 0 0 0
학생 5 : 0 0 1 1 0

<<지난 주 출석률 리스트>>
1번 학생 : 5일 출석(100%)
2번 학생 : 4일 출석(80%)
3번 학생 : 3일 출석(60%)
4번 학생 : 1일 출석(20%)
5번 학생 : 2일 출석(40%)

정답코드

import java.util.Scanner;
//1208_이서영
public class Attendance_1208_0724 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.print("학생 수 입력 : ");
        int student = scan.nextInt();
        int[][] studentarr;
        int sumarr[] = new int[student];
        studentarr = new int[5][student];

        System.out.println("<<지난  출석 데이터>>");
        for (int i = 0; i < student; i++) {
            System.out.print("학생 " + (i + 1) + " : ");
            for (int j = 0; j < student; j++) {
                studentarr[i][j] = scan.nextInt();
                sumarr[i] += studentarr[i][j];
            }
        }
        System.out.println(" ");
        System.out.println("<<지난  출석률 리스트>>");
        for (int i = 0; i < student; i++) {
            double back = (sumarr[i]/5.0)*100;
            System.out.println((i + 1) + "번 학생 : " + (int) sumarr[i] + "일 출석" + "(" + (int)(back) + "%)");
        }
    }
}

3. 영어 구문의 알파벳 합 구하기

파일명: Attitude_학번_제출날짜.java

설명

  • 알파벳 대소문자 관계없이 A~Z에 1~26 숫자를 대입한 뒤,
  • 영어 구문의 알파벳 점수 합을 출력함!

<<출력 결과>>
영어 구문 입력 : abc
abc : 6

영어 구문 입력 : AbC
AbC : 6

영어 구문 입력 : Attitude
Attitude : 100

영어 구문 입력 : I Love You
I Love You : 124

정답코드

import java.util.Scanner;
//1208_이서영
public class Attitude_1208_0725 {
    public static void main(String[] args) {
        int apb[] = new int[26];
        int sum=0;
        Scanner scan = new Scanner(System.in);
        System.out.print("영어 구문 입력 : ");
        String sentence = scan.nextLine();
        String upperSentence = sentence.toUpperCase();
        for(int i=0;i<26;i++){
            apb[i] = (int)('A'+i);
        }
        for(int j=0;j<sentence.length();j++) {
            for (int i = 0; i < 26; i++) {
                if (upperSentence.charAt(j) == apb[i]) {
                    sum += (apb[i] - 64);
                }
            }
        }
        System.out.println(sentence+" : "+sum);
    }
}
    

4. 2진수를 입력받아 10진수로 변환

파일명: BinaryDecimal_학번_제출날짜.java

조건

  • 8비트 2진수 입력
  • 모두 양수로 처리함

<<출력 결과>>
2진수 : 10110101
10진수 : 181

2진수 : 00011001
10진수 : 25

정답코드

import java.util.Scanner;
//1208_이서영
public class BinaryDecimal_1208_0726 {
    public static void main(String[] args) {
        int i,k,sum=0,num2=0,temp=1;
        Scanner scan = new Scanner(System.in);

        System.out.print("2진수 입력 : ");
        num2 = scan.nextInt();
        int ten[] = new int[20];

        for(i=0;num2!=0;i++){
            ten[i]=num2%10;
            num2=num2/10;
        }

        for(k=0;k<i;k++){
            if(ten[k]==1){
                sum=sum+temp;
            }
            temp*=2;
        }

        System.out.println("10진수 : "+sum);
    }
}

5. 10진수를 2진수로 바꾸는 프로그램

파일명: DecimalBinary_학번_제출날짜.java

조건

  • 2진수는 배열에 저장 후 출력함

<<출력 결과>>
10진수 : 255
2진수 : 11111111

10진수 : 27
2진수 : 11011

10진수 : 13
2진수 : 1101

정답코드

import java.util.Scanner;
//1208_이서영
public class DecimalBinary_1208_0727 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int num=0,i,j;
        int two[] = new int[20];

        System.out.print("10진수 입력 : ");
        num = scan.nextInt();

        for(i=0;num!=0;i++){
            two[i]=num%2;
            num=num/2;
        }

        System.out.print("2진수:");
        for(j=i-1;j>=0;j--){
            System.out.print(two[j]);
        }
        System.out.println();
    }
}

6. 전기요금을 계산하는 프로그램

파일명: Electricity_학번_제출날짜.java

조건

  • 전기요금 = (기본요금 + (사용량 * kw당요금)) + 세금
  • 요금은 원 단위까지만 출력
  • 코드별 요금 적용기준은 다음과 같음

전기요금 기준표

구분코드번호기본요금kw당요금세금 비율
가정용11130원127.9원전체금액의 9%
산업용2660원88.5원전체금액의 8%
교육용3370원52.0원전체금액의 5%

<<출력 결과>>
코드번호 입력(1.가정용, 2.산업용, 3.교육용) : 1
전기사용량을 입력하세요(kw) : 100
전기요금은 15172원입니다.

정답코드

import java.util.Scanner;
//1208_이서영
public class Electricity_1208_0728 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.print("코드번호 입력(1.가정용, 2.산업용, 3.교육용) : ");
        double num = scan.nextInt();
        System.out.print("전기사용량을 입력하세요(kw) : ");
        double kwsent = scan.nextInt();
        double amount = 0;
        double principal;

        if(num==1){
            principal = 1130+(kwsent*127.9);
            amount = principal*1.09;
        }

        else if(num==2){
            principal = 660+(kwsent*88.5);
            amount = principal*1.08;
        }

        else if(num==3){
            principal = 370+(kwsent*52.0);
            amount = principal*1.05;
        }

        System.out.println("전기 요금은 "+(int)(amount)+"원입니다.");
    }
}

7. 도서 대출 확인 프로그램

파일명: index_학번_제출날짜.java

<<출력 결과>>
대여 가능한 5권의 도서명을 입력하세요.
1번째 : 자바의 정석
2번째 : 모순
3번째 : 듀얼 브레인
4번째 : 소년이 온다
5번째 : 쇼펜하우어 인생수업
찾는 책 제목을 입력하세요 : 자바의 정석
자바의 정석은(는) 대출 목록의 1번째에 있습니다.

정답코드

import java.util.Scanner;
//1208_이서영
public class ExamProcess_1208_0730 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.print("인원 수 입력 : ");
        int studentnum = scan.nextInt();
        int studetstring[][] = new int[studentnum][4];

        int max[] = new int[studentnum];
        int k=1;

        for(int i=0;i<studentnum;i++){
            System.out.println();
            System.out.println("<<학생"+(i+1)+">>");
            k=1;
            while(k!=4){
                System.out.print("과목"+(k)+" : ");
                studetstring[i][k]=scan.nextInt();
                if(studetstring[i][k]>100 || studetstring[i][k]<0){
                    System.out.println("다시 입력하세요");
                    continue;
                }
                else{
                    if(max[i]<studetstring[i][k]) max[i]=studetstring[i][k];
                    k++;
                }
            }
        }
        System.out.println();
        System.out.print("        "+"과목1"+"  "+"과목2"+"  "+"과목3"+"  "+"기준점수"+"  "+"평점");
        for(int i=0;i<studentnum;i++){
            System.out.println();
            System.out.print("학생"+(i+1)+" :");
            for(int j=1;j<=3;j++){
                System.out.print("    "+studetstring[i][j]);
            }
            System.out.print("     "+max[i]);
            if(max[i]>=90) System.out.print("    "+"5.00");
            else if(max[i]>=80) System.out.print("    "+"4.00");
            else if(max[i]>=70) System.out.print("    "+"3.00");
            else if(max[i]>=60) System.out.print("    "+"2.00");
            else System.out.print("    "+"1.00");
        }

    }
}

8. 학급 성적 처리 프로그램

파일명: ExamProcess_학번_제출날짜.java

조건

  • 100보다 크거나 0보다 작은 수 입력 시 "다시 입력하세요"
  • 시험 3회 중 가장 높은 점수를 기준점수로 사용
  • 기준점수에 따라 평점 계산 (소수점 2자리까지)

평점 기준표

기준점수평점
90 ~ 100점5.0
80 ~ 89점4.0
70 ~ 79점3.0
60 ~ 69점2.0
0 ~ 59점1.0

<<출력 결과>>
인원 수 입력 : 2

<<학생1>>
과목1 : 110
다시 입력하세요
과목1 : 10
과목2 : 970
다시 입력하세요
과목2 : -3
다시 입력하세요
과목2 : 37
과목3 : 46

<<학생2>>
과목1 : 900
다시 입력하세요
과목1 : 90
과목2 : 13
과목3 : 57

과목1 과목2 과목3 기준점수 평점
학생1 : 1 0 37 46 46 1.00
학생2 : 90 13 57 90 5.00

정답코드

import java.util.Scanner;
//1208_이서영
public class index_1208_0729{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.println("대여 가능한 5권의 도서명을 입력하세요.");
        String[] canbook = new String [5];
        int check=0;
        for(int i=0; i<5; i++){
            System.out.print((i+1)+"번째 : ");
            canbook[i] = scan.nextLine();
        }
        System.out.println(" ");
        System.out.print("찾는 책 제목을 입력하세요 : ");
        String findbook = scan.nextLine();



        for(int j=0; j<5 ;j++){
            if(canbook[j].equals(findbook)){
                check = j+1;
                break;
            }
            else {
                check = 0;
            }
        }

        if(check == 0){
            System.out.println("해당 도서는 대출 목록에 없습니다.");
        }

        else{
            System.out.println(canbook[check-1]+"은(는) 대출 목록의 "+check+"번째에 있습니다.");
        }
    }
}


9. 문자열 내 알파벳 개수 세기

파일명: InString_학번_제출날짜.java

조건

  • 공백 포함 입력 가능
  • 대소문자 구분 없이 각 알파벳 개수 출력

<<출력 결과>>
문자열 입력 : Java
A : 2
J : 1
V : 1

문자열 입력 : Mirim Meister high School
C : 1
E : 2
G : 1
H : 3
I : 4
L : 1
M : 3
O : 2
R : 2
S : 2
T : 1

정답코드

import java.util.Scanner;
//1208_이서영
public class InString_1208_0731 {
    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);
        char alp[] = new char [26];
        for(int i=0; i<26; i++){
            alp[i] = (char)('A'+i);
        }
        int n[] = new int[26];

        System.out.print("문자열 입력 : ");
        String scanstring = scan.nextLine();
        String s;
        int m=0;
        char k;

        for(int i=0;i<scanstring.length();i++){
            k=scanstring.charAt(i);
            k=Character.toUpperCase(k);
            for(int j=0;j<26;j++){
                if(k==alp[j]){
                    n[j]++;
                    if(m<j) {
                        m = j;
                    }
                }
            }
        }
        for(int i=0;i<=m;i++){
            if(n[i]>=1){
                if(i==m) System.out.print(alp[i]+" : "+n[i]);
                else System.out.println(alp[i]+" : "+n[i]);
            }
        }
    }
}


10. 수 N 반복 더해서 백만 넘는 시점 출력

파일명: Number_학번_제출날짜.java

<<출력 결과>>
수 입력 : 4
1회 : 4
2회 : 4 + 44 = 48
3회 : 4 + 44 + 444 = 492
4회 : 4 + 44 + 444 + 4444 = 4936
5회 : 4 + 44 + 444 + 4444 + 44444 = 49380
6회 : 4 + 44 + 444 + 4444 + 44444 + 444444 = 493824
7회 : 4 + 44 + 444 + 4444 + 44444 + 444444 + 4444444 = 4938268

수 입력 : 9
1회 : 9
2회 : 9 + 99 = 108
3회 : 9 + 99 + 999 = 1107
4회 : 9 + 99 + 999 + 9999 = 11106
5회 : 9 + 99 + 999 + 9999 + 99999 = 111105
6회 : 9 + 99 + 999 + 9999 + 99999 + 999999 = 1111104

정답코드

import java.util.Scanner;
//1208_이서영
public class Number_1208_0801 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.print("수 입력 : ");
        int scannum = scan.nextInt();
        System.out.println();

        int count = 0,num=0,sum=0,arr[];
        String p = Integer.toString(scannum);
        String k="";

        while(true){
            k+=p;
            num=Integer.parseInt(k);
            sum+=num;
            if(sum>=10000000) break;
            count++;
        }

        //초기화하기
        k="";
        sum=0;
        arr = new int[count];
        int i=0;

        while(true){
            k+=p;
            num=Integer.parseInt(k);
            sum+=num;
            if(sum>=10000000){
                break;
            }
            arr[i] = num;
            System.out.print((i+1)+"회 : ");

            for(int j=0;j<=i;j++){
                if(j!=count-1){
                    if(i==0) System.out.println(sum);
                    else if(o==i) System.out.println(arr[o]+" = "+sum);
                    else System.out.print(arr[o]+" + ");
                }
                else{
                    if(i==0) System.out.println(sum);
                    else if(o==i) System.out.print(arr[o]+" = "+sum);
                    else System.out.print(arr[o]+" + ");
                }

            }
            i++;
        }
    }
}

11. 비밀번호 확인 프로그램

파일명: Password_학번_제출날짜.java

조건

  • while문으로 반복 입력
  • 숫자로만 된 비밀번호가 맞을 때까지 반복

<<출력 결과>>
비밀번호를 설정하세요 : 100479
비밀번호 설정이 완료되었습니다.

비밀번호를 입력하세요 : 13579
잘못된 비밀번호입니다. 다시 입력하세요.

비밀번호를 입력하세요 : 1004779
잘못된 비밀번호입니다. 다시 입력하세요.

비밀번호를 입력하세요 : 100479
로그인을 완료하였습니다.

비밀번호를 설정하세요 : 1220
비밀번호 설정이 완료되었습니다.

비밀번호를 입력하세요 : 302
잘못된 비밀번호입니다. 다시 입력하세요.
비밀번호를 입력하세요 : 1234
잘못된 비밀번호입니다. 다시 입력하세요.
비밀번호를 입력하세요 : 1212
잘못된 비밀번호입니다. 다시 입력하세요.
비밀번호를 입력하세요 : 1220
로그인을 완료하였습니다.

정답코드

import java.util.Scanner;
//1208_이서영
public class Password_1208_0802 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int i=1,password,scanpassword;
        System.out.print("비밀번호를 설정하세요 : ");
        password = scan.nextInt();
        System.out.println("비밀번호 설정이 완료되었습니다.");
        System.out.println(" ");
        while (true){
            System.out.print("비밀번호를 입력하세요 : ");
            scanpassword = scan.nextInt();
            if(scanpassword==password){
                System.out.println("로그임을 완료하였습니다.");
                System.out.println(" ");
                break;
            }
            else {
                System.out.println("잘못된 비밀번호입니다. 다시 입력하세요.");
                System.out.println(" ");
            }
        }
    }
}

12. 시험점수 최고/최저/평균 계산 프로그램

파일명: Score_학번_제출날짜.java

조건

  • 5개의 점수를 배열에 저장
  • 최고점, 최저점, 평균 출력

<<출력 결과>>
1번째 시험점수 : 54
2번째 시험점수 : 67
3번째 시험점수 : 73
4번째 시험점수 : 92
5번째 시험점수 : 81
시험점수 : 54 67 73 92 81
최고점 : 92
최저점 : 54
평균 : 73.4

1번째 시험점수 : 52
2번째 시험점수 : 68
3번째 시험점수 : 77
4번째 시험점수 : 95
5번째 시험점수 : 89
시험점수 : 52 68 77 95 89
최고점 : 95
최저점 : 52
평균 : 76.2

정답코드

import java.util.Scanner;
//1208_이서영
public class Score_1208_0803 {
    public static void main(String[] args) {
        Scanner scan  = new Scanner(System.in);
        int[] score = new int[5];
        double sum=0;
        for(int i=0 ; i<5; i++){
            System.out.print((i+1)+"번째 시험점수 : ");
            score[i] = scan.nextInt();
            sum+=score[i];
        }

        int max = score[0];
        int min = score[0];

        System.out.print("시험점수 : ");
        for(int j=0; j<5; j++){
            System.out.print(score[j]+" ");
        }
        System.out.println(" ");

        for(int k=1; k<5; k++){
            if(score[k]>max) {
                max = score[k];
            }
        }

        for(int k=1; k<5; k++){
            if(score[k]<min) {
                min = score[k];
            }
        }

        System.out.println("최고점 : "+max);
        System.out.println("촤저점 : "+min);
        System.out.println("평균 : "+(sum/5.0));
    }
}

13. 배열 A, B 병합 정렬 프로그램

파일명: SortMerge_학번_제출날짜.java

조건

  • 배열 A(5), B(5)를 각각 오름차순 정렬 후 병합
  • 동일한 데이터는 한 번만 출력 (중복 제거)

<<출력 결과>>
A 데이타 5개 입력 : 1 2 3 4 5
B 데이타 5개 입력 : 7 6 5 4 3
정렬 후 A 데이타 : 1 2 3 4 5
정렬 후 B 데이타 : 3 4 5 6 7
병합된 데이타 : 1 2 3 4 5 6 7

A 데이타 5개 입력 : 89 45 39 9 13
B 데이타 5개 입력 : 49 5 13 45 77
정렬 후 A 데이타 : 9 13 39 45 89
정렬 후 B 데이타 : 5 13 45 49 77
병합된 데이타 : 5 9 13 39 45 49 77 89

정답코드

import java.util.Scanner;
//1208_이서영
public class SortMerge_1208_0804 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int a[] = new int[5];
        int b[] = new int[5];
        int len=10;
        int merge[] = new int[len];
        int last[] = new int[10];
        System.out.print("A 데이타 5개 입력 : ");
        for(int i=0;i<5;i++){
            a[i]=scan.nextInt();
            merge[i]=a[i];
        }
        System.out.print("B 데이타 5개 입력 : ");
        for(int i=0;i<5;i++){
            b[i]=scan.nextInt();
            merge[i+5]=b[i];
        }

        System.out.println();
        int temp=0;

        for(int i=0;i<5;i++){
            for(int j=0;j<5;j++){
                if(a[i]<a[j]){
                    temp=a[i];
                    a[i]=a[j];
                    a[j]=temp;
                }
                if(b[i]<b[j]){
                    temp=b[i];
                    b[i]=b[j];
                    b[j]=temp;
                }
            }
        }
        for(int i=0;i<10;i++){
            for(int j=0;j<10;j++){
                if(merge[i]<merge[j]){
                    temp=merge[i];
                    merge[i]=merge[j];
                    merge[j]=temp;
                }
            }
        }
        int cnt=0;

        for(int i=0;i<9;i++){
            if(merge[i]==merge[i+1]){
                len--;
                continue;
            }
            last[cnt]=merge[i];
            cnt++;
        }
        last[cnt]=merge[9];

        System.out.print("정렬 후 A 데이타  : ");
        for(int i=0;i<5;i++){
            if(i==4) System.out.print(a[i]);
            else System.out.print(a[i]+" ");
        }
        System.out.println();

        System.out.print("정렬 후 B 데이타  : ");
        for(int i=0;i<5;i++){
            if(i==4) System.out.print(b[i]);
            else System.out.print(b[i]+" ");
        }
        System.out.println();
        System.out.print("병합된 데이타  : ");
        for(int i=0;i<len;i++){
            if(i==len-1) System.out.print(last[i]);
            else System.out.print(last[i]+" ");
        }
    }
}


여름방학 숙제로 1학기 자바 수행평가를 다시 풀어보는 활동을 진행했습니다!
헷갈리는 부분을 다시 복습할 수 있는 기회가 된 것 같아요..!

그러면 우리 모두 즐코!

0개의 댓글