목록java (23)
develope_kkyu
import java.time.Duration; import java.time.LocalDateTime; import java.time.Period; import java.time.temporal.ChronoUnit; public class DateTimeCompareExam { public static void main(String[] args) { LocalDateTime startTime = LocalDateTime.of(2023, 1, 1, 9, 0, 0); LocalDateTime endTime = LocalDateTime.of(2024, 12, 31, 23, 59, 59); System.out.println("시작시간 : " + startTime); System.out.println("종료시간..
import java.util.Calendar; public class CalenderExam { public static void main(String[] args) { Calendar now = Calendar.getInstance(); //System.out.println (now); System.out.println (now.toString()); int year = now.get(Calendar.YEAR); // 2022 int month = now.get(Calendar.MONTH) + 1; // Calendar.MONTH는 0에서부터 시작 ==> 9 int day = now.get(Calendar.DAY_OF_MONTH); // 21 int week = now.get(Calendar.DAY_..
Accoung.java public class Account { private String ano; private String owner; private int balance; private int password; public Account(String ano, String owner, int balance, int password) { this.ano = ano; this.owner = owner; this.balance = balance; this.password = password; } public String getAno() { return ano;// this.ano } public void setAno(String ano) { this.ano = ano; } public String getO..
Account.java public class Account { private String ano; private String owner; private int balance; public Account(String ano, String owner, int balance) { this.ano = ano; this.owner = owner; this.balance = balance; } public String getAno() { return ano;// this.ano } public void setAno(String ano) { this.ano = ano; } public String getOwner() { return owner;// this.owner } public void setOwner(Str..
public static void main(String[] args) { // for문은 활용하여 1~100까지의 누적합 구하기. int total = 0; int index;// for문 밖에서 index를 사용하는 부분이 있기 때문에 변수 선언은 for문 밖에서 사용. for (index=1; index 초기값을 설정 // index 반복에 대한 조건. // index++ ==> for문 마감시 처리하는 실행문 total = total + index; System.out.printf("%d번째까지의 누적합 %d입니다. \n", index, total); } System.out.printf("index = %d \t total=%d \n", index-1, total); } -- 1번째까지의 누적합 1..
public static void main(String[] args) { // 점수가 60점 이상이면 합격, 그 중에서도 90점 이상일 경우 장학생여부 판별하는 프로그램 // 60점 이하면 불합격 그 중에서도 40점 이하일 경우는 5년내 시험 자격불가 int score = 40; System.out.printf("score = %d \n", score); if (score >= 60) { // 60보다 클 경우 실행문 System.out.println("당신은 합격하셨습니다."); if (score >= 90) { // 90보다 클 경우 장학생에 관련 로직 System.out.println("당신은 장학생이 되셨습니다."); } else { System.out.println("아쉽게도 장학생은 아닙니다...
public static void main(String[] args) { int human1 = 99; int result1 = ++human1 * 10; //위 한줄은 아래 2줄과 같은 의미임. // human1 = human+1;==> human1 = 100; // int result1 = human1 * 10;==> result1 = 1000; System.out.printf("human1 = %d, result1 = %d \n", human1, result1); int human2 = 99; int result2 = human2++ * 10; // int result2 = human2 * 10;==> result2 = 990; // human2 = human2 + 1;==> human2 = 100..
public static void main(String[] args) { Scanner sc = new Scanner(System.in);// 키보드로부터 입력받겠다. int age; System.out.print("당신의 나이를 입력하세요."); age = sc.nextInt();//정수만 받음 System.out.printf("당신의 나이는 %d세입니다. \n", age); sc.nextLine();// 강제로 찌꺼기 소화. System.out.print("당신의 이름은? ==>"); String name; name = sc.nextLine();//문자형으로 받음 System.out.printf("당신의 이름은 %s입니다.\n", name); System.out.print("오늘의 온도는? ==>")..
MyPoint.java public class MyPoint { public int x; public int y; MyPoint(int x, int y){ this.x = x; this.y = y; } public double getDistance(int i, int j) { double dis; dis = Math.sqrt((this.x-i)*(this.x-i) + (this.y-j)*(this.y-j)); return dis; } } MyPointExam.java public class MyPointExam { public static void main(String[] args) { //System.out.println(Math.sqrt(4));// 2.0*2.0 == 4 //System.out.pr..
public static void main(String[] args) { // 최대, 최소, 합계를 구하는 프로그램(함수를 이용) int max, min, sum; int [] arr1 = {1,5,3,8,2}; max = searchMax(arr1); min = searchMin(arr1); sum = doSum(arr1); System.out.printf("MAX = %d\n", max); System.out.printf("MIN = %d\n", min); System.out.printf("SUM = %d\n", sum); int [] arr2 = {10,20,5,30,1,-99,100}; max = searchMax(arr2); min = searchMin(arr2); sum = doSum(arr2..