19050104_Day24 알고리즘
알고리즘
입출력 fileCopySpeedTest는 이해하기, 최소 외우기
세 값의 최대값(3개의 정수값을 입력하고 최대값 구하기), Scanner 사용한 콘솔 입력
//내가 한거 package j0514; import java.util.Scanner; public class MaxValuePrint { Scanner sc = new Scanner(System.in); int a,b,c,d; public MaxValuePrint() { System.out.println("세 정수의 최대값을 구합니다."); System.out.println("세 개의 수를 입력해 주세요"); a = sc.nextInt(); b = sc.nextInt(); c = sc.nextInt(); if(a > b) { if(a>c) { d = a; }else { d = c; } }else { if(b>c) { d = b; }else { d = c; } } System.out.println("최댓값은 " + d + "입니다."); } public static void main(String[] args) { new MaxValuePrint(); } }
//선생님 풀이 package j0514; import java.util.Scanner; public class MaxValuePrintT { Scanner sc = new Scanner(System.in); int a,b,c,max; public MaxValuePrintT() { System.out.println("세 정수의 최대값을 구합니다."); System.out.println("세 개의 수를 입력해 주세요"); a = sc.nextInt(); b = sc.nextInt(); c = sc.nextInt(); max = a; if(max<b) max = b; if(max<c) max = c; System.out.println("최댓값은 " + max + "입니다."); } public static void main(String[] args) { new MaxValuePrintT(); } }
- 순서도의 기호
- 정의,분석,해법을 '그림'으로!
printf() 메소드 : 출력형식(자릿수, 정렬)을 표현하기에 적합
형식) printf("%d,%f,%s,%c", 포맷스트링 수만큼 매핑되는 데이터)
%문자 => 포맷스트링
정수 : %d
실수 : %f
문자 : %c
문자열 : %s
<데이터가 저장되는 위치에 따라 이름이 달라요~!>
문제 ) 정수값을 화면에 출력하시오
데이터 300
System.out.print(300);
데이터 int su = 300;
System.out.print(su);
데이터 int []su = {300};
System.out.println(su[0]);
데이터 Vector
v = new Vector; v.add(300);
데이터 class Person{ int su = 300 ; }
Person p = new Person();
System.out.print(p.su);
-2 데이터 public class Person{ private int su = 300; public int getsu(){retrurn su;}}
Person p = new Person();
System.out.println(p.getSu());
Person [] arr = {p, new Person()};
System.out.println(arr[0].getSu());
Vector
v = new Vector<>(); v.add(p);
v.add(new Person());
System.out.println(v.get(0).getSu());