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 | 31 |
Tags
- emmet환경설정
- 국취제
- 내일배움카드
- forward
- 관리자회원조회
- Git
- 국비학원
- 입력메소드
- github
- 권한변경
- 비밀번호암호화
- mvc
- 내배카
- 로그아웃
- 국민취업지원제도
- 비밀번호변경
- 정처기
- redirect
- 회원정보수정
- 인코딩
- 별찍기
- 페이지 재사용
- 검색기능
- jsp기본
- 회원탈퇴
- 배열
- jdbc설정
- live server 환경설정
- jdbc환경설정
- 페이징
Archives
- Today
- Total
기록
*4일차 실습 본문
[문제 1]
국영수,총점,평균을 정수 및 실수로 변수 선언하고 키보드로 입력, 합계와 평균 계산
이를 가지고 합격출력
(합격조건: 세 과목 점수가 각각 40점 이상이면서 , 평균이 60점 이상이면 합격 아니면 불합격)
[문제 2]
변수 선언하고 키보드로 입력받은 값을 변수에 기록후 변수값을 출력
성별이 'M'이면 남학생, 'M'이 아니면 여학생으로 출력
변수선언 후 입력받음
학생이름 , 학년 , 반 , 번호 , 성별(M/F) , 성적
[문제 3]
ㄱ.정수 변수 선언 ㄴ.키보드로 정수 입력받음 ㄷ.입력받은 정수가 양수면 양수, 양수가 아니면 양수가 아니다 출력
[문제 4]
ㄱ.정수 변수 선언
ㄴ.문자열 변수 선언
ㄷ.키보드로 정수 입력받음
ㄹ.입력받은 정수가 짝수면 "짝수"를 문자열 변수에 기록, 짝수가 아니면 "홀수"를 기록하고 문자열변수 값 출력
(짝수 조건: 어떤 수를 2로 나눈 나머지가 0과 같으면 짝수)
package com.kh.function;
import java.util.Scanner;
public class Example {
public void opSample1() {
Scanner sc =new Scanner(System.in);
System.out.print("국어 점수: ");
int kor= sc.nextInt();
System.out.print("영어 점수: ");
int eng= sc.nextInt();
System.out.print("수학 점수: ");
int math = sc.nextInt();
int total = kor+eng+math;
double avg = ((total) / 3);
System.out.printf("총점: %d%n",total);
System.out.printf("평균: %.2f%n",avg);
String pass = (kor>=40 && eng>=40 && math>=40 && avg>=60) ? "합격" : "불합격";
System.out.println(pass);
System.out.println("---------------");
}
public void opSample2() {
Scanner sc =new Scanner(System.in);
System.out.print("학생이름: ");
String name = sc.nextLine();
System.out.print("학년: ");
int grade= sc.nextInt();
System.out.print("반: ");
int cla= sc.nextInt();
System.out.print("번호: ");
int num= sc.nextInt();
System.out.print("성별(M/F): ");
char gender= sc.next().charAt(0);
String gen = gender == 'M' ? "남학생" : "여학생";
System.out.print("성적: ");
double score = sc.nextDouble();
System.out.printf("%d학년 %d반 %d번 %s %s은(는) 성적이 %.2f이다.%n",grade,cla,num,gen,name,score);
System.out.println("---------------");
}
public void opSample3() {
Scanner sc =new Scanner(System.in);
System.out.print("정수: ");
int num = sc.nextInt();
String result = num > 0 ? "양수다" : "양수가 아니다";
System.out.println(result);
System.out.println("---------------");
}
public void opSample4() {
Scanner sc =new Scanner(System.in);
System.out.print("정수: ");
int num = sc.nextInt();
String result = (num%2 == 0) ? ("짝수다") : ("홀수다");
System.out.println(result);
System.out.println("---------------");
}
}