반응형
풀이
더보기
import java.util.Scanner;
public class Quiz01 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.print("제곱값을 구할 숫자를 입력하세요: ");
int num = scan.nextInt();
System.out.println(num + "의 제곱은 " + getSquared(num) + "이다.");
}
public static int getSquared(int x) {
return (int) Math.pow(x, 2);
}
}
풀이
더보기
import java.util.Scanner;
public class Quiz01 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.print("점수를 입력하세요: ");
int score1 = scan.nextInt();
int score2 = scan.nextInt();
int score3 = scan.nextInt();
int score4 = scan.nextInt();
System.out.println("평균은 " + getAverage(score1, score2, score3, score4));
}
public static double getAverage(int score1, int score2, int score3, int score4) {
return (score1 + score2 + score3 + score4)/(double)4;
}
}
풀이
더보기
import java.util.Scanner;
public class Quiz01 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.print("숫자와 나눌 수를 입력하세요: ");
int num = scan.nextInt();
int divideNum = scan.nextInt();
printQuotientRemainder(num, divideNum);
}
public static void printQuotientRemainder(int number1, int number2) {
int quotient = number1 / number2;
int remainder = number1 % number2;
System.out.println("몫: " + quotient);
System.out.println("나머지: " + remainder);
}
풀이
더보기
import java.util.Scanner;
public class Quiz01 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.print("숫자를 입력하세요: ");
int num = scan.nextInt();
isEven(num);
}
public static boolean isEven(int a) {
if (a % 2 == 0) {
return true;
}
return false;
}
}
반응형
'Algorithm > etc' 카테고리의 다른 글
[코딩연습] 배열 연습 (0) | 2021.11.04 |
---|---|
[코딩연습] 메소드 생성 연습 2 (0) | 2021.11.03 |
[코딩연습] if문 ~ switch문 (0) | 2021.10.20 |
[코딩연습] switch 문 (0) | 2021.10.20 |
[코딩연습] if문과 논리연산자 (0) | 2021.10.20 |