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
- 적용
- 모달팝업
- while
- 반복문
- dowhile
- 자바연산자
- node.js
- 레이어팝업
- 백준
- for
- 프로그래머스
- 문제풀이
- 자바변수
- 배열
- 레이어팝업URL
- berak
- array
- Spring
- URL생성
- 자바
- LV1
- 자바실습문제
- Java
- CONTINUE
- 키패드
- KH정보교육원
- express
- 정적파일
- 분기문
- 2차원배열
Archives
- Today
- Total
까잉이의 개발노트
JAVA 연산자 실습문제 본문
1. 키보드로입력받은하나의정수가양수이면“양수다“, 양수가아니면“양수가아니다“를출력하세요.
public void practice1() {
Scanner sc = new Scanner(System.in);
System.out.print("정수 입력 : ");
int num = sc.nextInt();
String result = num >= 0 ? "양수다" : "양수가 아니다";
System.out.println(result);
}
2. 키보드로입력받은하나의정수가양수이면“양수다“, 양수가아닌경우중에서0이면“0이다“, 0이아니면“음수다”를출력하세요.
public void practice2() {
Scanner sc = new Scanner(System.in);
System.out.print("정수 입력 : ");
int num = sc.nextInt();
String result = num > 0 ? "양수다" : (num == 0 ? "0이다" : "음수다");
System.out.println(result);
}
3. 키보드로입력받은하나의정수가짝수이면“짝수다“, 짝수가아니면“홀수다“를출력하세요.
public void practice3() {
Scanner sc = new Scanner(System.in);
System.out.print("정수 입력 : ");
int num = sc.nextInt();
String result = num/2 == 0 ? "짝수다" : "홀수다";
System.out.println(result);
}
4. 모든사람이사탕을골고루나눠가지려고한다. 인원수와사탕개수를키보드로입력받고1인당동일하게나눠가진사탕개수와나눠주고남은사탕의개수를출력하세요.
public void practice4() {
Scanner sc = new Scanner(System.in);
System.out.print("인원수 입력 : ");
int people = sc.nextInt();
System.out.print("사탕수 입력 : ");
int candy = sc.nextInt();
int nanum = candy / people;
int nam = candy % people;
System.out.println("1인당 사탕 개수 : " + nanum);
System.out.println("남는 사탕 개수 : " + nam);
}
5. 키보드로입력받은값들을변수에기록하고저장된변수값을화면에출력하여확인하세요.이때성별이‘M’이면남학생, ‘M’이아니면여학생으로출력처리하세요.
public void practice5() {
Scanner sc = new Scanner(System.in);
System.out.print("이름 : ");
String name = sc.nextLine();
System.out.print("학년(숫자만) : ");
int year = sc.nextInt();
System.out.print("반(숫자만) : ");
int ban = sc.nextInt();
System.out.print("번호(숫자만) : ");
int num = sc.nextInt();
System.out.print("성별(M/F) : ");
char gender = sc.next().charAt(0);
String gender2 = gender == 'M' ? "남학생" : "여학생";
System.out.print("성적(소수점 아래 둘째자리까지) : ");
double grade = sc.nextDouble();
// System.out.println("이름 : " + name);
// System.out.println("학년 : " + year);
// System.out.println("반 : " + ban);
// System.out.println("번호 : " + num);
// System.out.println("성별 : " + gender2);
// System.out.printf("%s%.2f","성적 : ", grade);
System.out.printf("%d%s%d%s%d%s%s%s%s%s%.2f%s", year,"학년 ",ban,"반 ",num,"번 ",name," ",gender2,"의 성적은",grade,"이다.");
}
6. 나이를키보드로입력받아어린이(13세이하)인지, 청소년(13세초과~ 19세이하)인지, 성인(19세초과)인지출력하세요.
public void practice6() {
Scanner sc = new Scanner(System.in);
System.out.print("나이 : ");
int age = sc.nextInt();
String ageGubun = age <= 13 ? "어린이" : age > 13 && age <= 19 ? "청소년" : "성인";
System.out.println(ageGubun);
}
7. 국어, 영어, 수학에대한점수를키보드를이용해정수로입력받고, 세과목에대한합계(국어+영어+수학)와평균(합계/3.0)을구하세요.세과목의점수와평균을가지고합격여부를처리하는데세과목점수가각각40점이상이면서평균이60점이상일때합격, 아니라면불합격을출력하세요.
public void practice7() {
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 aver = (double)total / 3.0;
String pass = kor >= 40 && eng >= 40 && math >= 40 && aver >= 60 ? "합격" : "불합격";
System.out.println("합계 : " + total);
System.out.println("평균 : " + aver);
System.out.println(pass);
}
8. 주민번호를이용하여남자인지여자인지구분하여출력하세요.
public void practice8() {
Scanner sc = new Scanner(System.in);
System.out.print("주민번호를 입력하세요 : ");
char pnum = sc.next().charAt(7);
String gender = pnum == '1' ? "남자" : pnum == '2'? "여자" : "잘못입력하셨습니다.";
System.out.println(gender);
}
9. 키보드로정수두개를입력받아각각변수(num1, num2)에저장하세요.그리고또다른정수를입력받아그수가num1이하거나num2 초과이면true를출력하고아니면false를출력하세요.(단, 입력할때num1은num2보다작아야함)
public void practice9() {
Scanner sc = new Scanner(System.in);
System.out.print("정수1 입력 : ");
int num1 = sc.nextInt();
System.out.print("정수2 입력 : ");
int num2 = sc.nextInt();
System.out.print("정수3 입력 : ");
int num3 = sc.nextInt();
boolean result = num3 <= num1 || num3 > num2 ? true : false;
System.out.println(result);
}
10. 3개의수를키보드로입력받아입력받은수가모두같으면true, 아니면false를출력하세요.
public void practice10() {
Scanner sc = new Scanner(System.in);
System.out.print("정수1 입력 : ");
int num1 = sc.nextInt();
System.out.print("정수2 입력 : ");
int num2 = sc.nextInt();
System.out.print("정수3 입력 : ");
int num3 = sc.nextInt();
boolean result = num1 == num2 && num1 == num3 ? true : false;
System.out.println(result);
}
'JAVA' 카테고리의 다른 글
JAVA 반복문(for문, while문)과 분기문 정리 (0) | 2021.08.01 |
---|---|
JAVA 조건문(if문, switch문) 정리 (0) | 2021.07.28 |
JAVA 연산자 (0) | 2021.07.28 |
JAVA 변수(Variable) 실습문제 (0) | 2021.07.27 |
JAVA 변수(Variable) (0) | 2021.07.14 |
Comments