Git Product home page Git Product logo

score-average's Introduction

score-average

package examAverage; import java.util.Scanner;

public class Average { public static void main(String[] args) { // 우리반 국어 성적의 평균 구하기

	int[] kors = new int[5];
	Scanner sc = new Scanner(System.in); 
	int menu;
	boolean keepLoop = true;
	
	while(keepLoop) {
		// 메인메뉴
		System.out.printf("┌─────────── 0.main menu ───────────┐\n");
		System.out.printf("│   1.input    2.print    3.exit    │\n");
		System.out.printf("└───────────────────────────────────┘");		
		menu = sc.nextInt();
		
		switch(menu) {
			case 1 : // menu==1
				// 1. 성적 입력
				System.out.println("┌───────────────────────────────────┐");
				System.out.println("│           1.input score           │");
				System.out.println("└───────────────────────────────────┘");
				for(int i=0; i<kors.length; i++) {
					do {
						System.out.printf("input kor score!!");
						kors[i] = sc.nextInt();
						
						if(kors[i]<0 || kors[i]>100){
							//kors[i]가 0보다 작거나 100보다 클때
							System.out.println("range is 0~100");
						}				
					}while(kors[i]<0 || kors[i]>100);
				}
				System.out.println("────────────────────────────────────");
				System.out.println("────────────────────────────────────");
				break;
				
			case 2 : // menu==2
				// 2. 성적 출력
				System.out.println("┌───────────────────────────────────┐");
				System.out.println("│           2.print score           │");
				System.out.println("└───────────────────────────────────┘");
				
				int total=0;
				float avg;
				
				for(int i=0; i<kors.length; i++) {
					total = total + kors[i];
					// total +=kors[i];
				}
				
				avg = total/5f;
				
				for(int i=0; i<kors.length; i++) {
					System.out.printf("%d \t", kors[i]);
				}
				System.out.println();
				System.out.printf("total: %3d \n", total);
				System.out.printf("average: %6.2f \n", avg);
				System.out.println("────────────────────────────────────");
				System.out.println("────────────────────────────────────");
				break;
				
			case 3 : // menu==3
				System.out.println("ByeBye~");
				keepLoop = false;
				break;
				
			default : // menu가 1,2,3이 아닐경우
				System.out.println("range 1~3");
		}
	}		
}

}

score-average's People

Contributors

wjdgkdms avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.