반응형
가장 기본이 되는 객체지향 간단한 프로그램을 메서드로만 빼서 구현 해 보았다 이제 시작이다 객체지향 덤벼라
package file;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("큰 값을 찾는 프로그램입니다.");
System.out.println("두 수를 입력하세요: ");
int x =sc.nextInt();
int y =sc.nextInt();
int max=findMax(x,y);
System.out.printf("첫번째 문제 기능구현 Max: %d\n",max);
System.out.println("짝수인지 홀수인지 구해주는 프로그램입니다.");
System.out.println("아무 수나 입력해 주세요: ");
int a = sc.nextInt();
Boolean check = findValue(a);
System.out.println(check==true?"짝수":"홀수");
System.out.println("3의 배수인지 아닌지 구해주는 프로그램입니다.");
System.out.println("아무 수나 입력해 주세요: ");
int w = sc.nextInt();
Boolean checkT = findTvalue(w);
System.out.println(checkT==true?"3의배수입니다": "3의배수가 아닙니다.");
System.out.println("절대값을 구하는 함수를 정의하시오.");
System.out.println("수를 입력해주세여");
int q = sc.nextInt();
int z = getGuid(q);
System.out.println(z);
System.out.println("거꾸로수를 보내주는 프로글램입니다.");
int ge = sc.nextInt();
int get = getReverse(ge);
System.out.println(get);
System.out.println("소수를 구하는 프로그램입니다.");
System.out.println("수를 입력해주세요");
}
private static int getReverse(int ge) {
int x=0;
int w=0;
while(true){
x= ge%10;
ge= ge/10;
w=w*10+x;
if(ge==0)break;
}
return w;
}
private static int getGuid(int q) {
if(q>0)return q;
else return q*-1;
}
private static Boolean findTvalue(int w) {
if(w%3==0)return true;
else return false;
}
private static Boolean findValue(int a) {
if(a%2==0)return true;
else return false;
}
private static int findMax(int x, int y) {
return x>y?x:y;
}
}
반응형
'객체지향' 카테고리의 다른 글
태태코딩 - 객체지향 원칙 (0) | 2024.12.25 |
---|---|
구구단 프로그램(java) (0) | 2023.02.22 |
계산기 만들기 프로그램 (0) | 2023.02.22 |