자바문제 리스트
총점, 평균 구하기
import java.util.Scanner;
class Q_1
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
int kor, eng, mat;
int tot;
double avg;
System.out.print("국어/영어/수학: ");
kor = scan.nextInt();
eng = scan.nextInt();
mat = scan.nextInt();
tot = kor+eng+mat;
avg = (double)tot /3;
System.out.printf("총점은 %d \n", tot);
System.out.printf("평균은 %f \n", avg);
}
}
/*
1.국어,영어,수학 3개과목을 입력받아서
총점,평균 출력
1)변수선언
int kor,eng,mat;
int tot;//총점
double avg;//평균
2)입력
3)계산
4)출력
*/
권종별 수량 구하기
import java.util.Scanner;
class Q_2
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
System.out.print("금액을 입력하시오 : \n");
//int money=65700;//금액
int money=scan.nextInt();//입력금액
int money_50000;//5만원권 수량저장 변수
int money_10000;//1만원권 수량저장 변수
int money_5000;//5천원권 수량저장 변수
int money_1000;//1천원권 수량저장 변수
int money_500;//5백원권 수량저장 변수
int money_100;//1백원권 수량저장 변수
System.out.printf("%d의 권종별 수량은 \n", money);
money_50000 = money / 50000;//5만원권 수량계산
money = money % 50000;//나머지 금액
System.out.printf("5만원권 수량은 : %d \n", money_50000);
money_10000 = money / 10000;//1만원권 수량계산
money = money % 10000;//나머지 금액
System.out.printf("1만원권 수량은 : %d \n", money_10000);
money_5000 = money / 5000;//5천원권 수량계산
money = money % 5000;//나머지 금액
System.out.printf("5천원권 수량은 : %d \n", money_5000);
money_1000 = money / 1000;//1천원권 수량계산
money = money % 1000;//나머지 금액
System.out.printf("1천원권 수량은 : %d \n", money_1000);
money_500 = money / 500;//5백원권 수량계산
money = money % 500;//나머지 금액
System.out.printf("5백원권 수량은 : %d \n", money_500);
money_100 = money / 100;//5만원권 수량계산
money = money % 100;//나머지 금액
System.out.printf("1백원권 수량은 : %d \n", money_100);
}
}
/*
2.금액을 입력받는다.권종별 수량구하기
1)변수선언
int money=65700;
int money_50000;//50000만원권 수량저장변수
2)권종수량계산 ( / % )
money_50000 = money / 50000;//5만원권 수량계산
money = money % 50000; //나머지 금액
*/
원둘레, 원면적, 구부피 구하기
import java.util.Scanner;
class Q_3
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
//double radius = 10; //반지름
double radius = scan.nextInt();
double PI = Math.PI;
double 원둘레 = 2 * PI * radius; //원둘래
double 원면적 = radius*radius*PI; //원면적
double 구부피 = ((4/3)*PI)*radius*radius*radius; //구부피
System.out.printf("원둘레 %f\n", 원둘레);
System.out.printf("원면적 %f\n", 원면적);
System.out.printf("구부피 %f\n", 구부피);
System.out.printf("PI 값은 %f\n", PI);
}
}
// ^3의 의미 : 3번 곱하라는 의미
/*
3.반지름입력받는다(double radius)
원둘레: 2 * PI * radius
원면적: radius*radius*Math.PI
구부피: 4/3*PI*radius^3
*/
큰수를 세 개 입력하여 큰 수 알아내기
import java.util.Scanner;
class Q_4
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
int a=scan.nextInt(); // 키보드로 입력받음
int b=scan.nextInt();
int c=scan.nextInt();
int d;
/*
d = (a>b) ? a : b;
d = (b>c) ? b : c;
d = (a>c) ? a : c;
*/
// 아래는 축소시킨 코드
d = (a>b) ? a : b;
d = (d>c) ? d : c;
System.out.printf("%d, %d, %d의 세 중 큰 수는 %d", a, b, c, d);
}
}
/*
// 3개의 수(a,b,c) 를 입력받아서 큰수 구하기
// 변수 = (조건) ? 참값 : 거짓값
int a=10, b=5, c;
// 두 수중에 큰 수 구하기
c = ( a>b ) ? a : b;
System.out.printf("%d와 %d 중 큰수는 %d\n", a, b, c);
*/
출생년도를 기준으로 현재 나이 구하기
import java.util.Calendar;
import java.util.Scanner;
class Q_5
{
public static void main(String[] args)
{
int year = Calendar.getInstance().get(Calendar.YEAR);
Scanner scan = new Scanner(System.in);
System.out.printf("당신의 출생년도를 입력하세요 : ");
int birthday = scan.nextInt();
int total = (year-birthday)+1;
System.out.printf("당신의 나이는 %d \n", total);
}
}
// 6. 출생년도를 기준으로 띠 구하기