본문 바로가기

Programming/Java45

[JAVA] 데이터 타입과 형변환 [JAVA] - 출력과 선언 규칙 JAVA 11 jdk 설치 방법 JAVA 11 설치방법 https://www.oracle.com/ Oracle | Cloud Applications and Cloud Platform Oracle condemns the terrorist attacks against Israel and its citizens. Oracle will provide all support necessary to its employees and to t hong-study.tistory.com 데이터 타입 자바에서 '데이터 타입'은 해당 데이터가 메모리에 어떻게 저장되고 프로그램에서 어떻게 처리되어야 하는지를 명시적으로 알려주는 것이다. 정수형 데이터 타입 정수형의 데이터 타입에 아래와 같이 4가.. 2023. 10. 25.
[JAVA] - 출력과 선언 규칙 JAVA 11 jdk 설치 방법 JAVA 11 설치방법 https://www.oracle.com/ Oracle | Cloud Applications and Cloud Platform Oracle condemns the terrorist attacks against Israel and its citizens. Oracle will provide all support necessary to its employees and to the government of Israel an hong-study.tistory.com 출력문 Print System.out.print() System.out.println() System.out.printf() ● 출력문의 차이 println : 가장 마지막에 개행이 추가되어 출.. 2023. 10. 25.
JAVA 11 jdk 설치 방법 JAVA 11 설치방법 https://www.oracle.com/ Oracle | Cloud Applications and Cloud Platform Oracle condemns the terrorist attacks against Israel and its citizens. Oracle will provide all support necessary to its employees and to the government of Israel and the country’s defense establishment. Magen David Adom, a nonprofit providing Israeli cit www.oracle.com Oracle 홈페이지 접속 Oracle 접속 화면 좌측 상단 "Products".. 2023. 10. 25.
선택 정렬 알고리즘 배열에 저장된 값을 오름차순으로 정렬한 후 출력하는 프로그램 선택 정렬 알고리즘은 첫 번째 자료를 두 번째 자료로부터 마지막 자료까지 차례대로 비교하여 가장 작은 값을 찾아 첫 번째에 놓고, 두 번째 자료를 세 번째 자료부터 마지막 자료까지와 차례대로 비교하여 그 중 가장 작은 값을 찾아 두 번째 위치에 놓는 과정을 반복하며 정렬을 수행 1회전 수행 후 가장 작은 값의 자료가 맨 앞에 오게 되므로 그 다음 회전에서는 두 번째 자료를 가지고 비교한다. 코드 1 public class Test{ 2 public static void main(String[] args){ 3 int E[] = { 95, 75, 85, 100, 50 }; 4 int i =0; 5 int Temp = 0; 6 do{ 7 int j.. 2020. 10. 20.
1~100범위 안에 가장 큰 소수 구하기 소수는 자신보다 작은 두 개의 자연수를 곱하여 만들 수 없는 1보다 큰 자연수이다. 예를 들어, 5는 1×5 또는 5×1로 수를 곱한 결과를 적는 유일한 방법이 그 수 자신을 포함하기 때문에 5는 소수이다. 그러나 6은 자신보다 작은 두 숫자(2×3)의 곱이므로 소수가 아닌데, 이렇듯 1보다 큰 자연수 중 소수가 아닌 것은 합성수라고 한다. 1과 그 수 자신 이외의 자연수로는 나눌 수 없는 자연수로 정의하기도 한다. 문제의 코드는 소수인지 판별하기 위해 제곱근까지의 숫자로 나누어 떨어지는 지 검사한다. 제곱근까지의 수 중 한 개의 수에 대해서라도 나누어 떨어지면 소수가 아니다. 예를 들어 25는 2,3,4,5로 나누었을 때 5로 나누어 떨어지므로 소수가 아니고, 41은 2,3,4,5,6으로 나누어도 한 .. 2020. 10. 20.
push, pop 코드 1 public class P{ 2 static int Stack[] new int[5]; 3 static int Top = -1; 4 public static void main(String[] args){ 5 push(100); 6 push(110); 7 push(120); 8 pop(); 9 push(130); 10 push(140); 11 pop(); 12 } 13 static void push(int i){ 14 Top++; 15 if(Top >= 5) 16 System.out.printf("overflow"); 17 else 18 Stack[Top] = i; 19 } 20 static void pop(){ 21 if(Top < 0) 22 System.out.printf("underflow".. 2020. 10. 20.
외부클래스 코드 1 class Inclass{ 2 int a,b,c; 3 } 4 public class Problem{ 5 public static void main(String[] args){ 6 Inclass V = new Inclass(); 7 V.a = 10; 8 V.b = 20; 9 prnt(V); 10 System.out.printf("a=%d, b=%d, c=%d\n", V.a, V.b, V.c); 11 } 12 static void prnt(Inclass V){ 13 V.a += 30; 14 V.b -= 30; 15 if(V.a 2020. 10. 20.
실행 클래스 내부에 메소드 정의 코드 1 public class Problem{ 2 public static void main(String[] args){ 3 int a,b,c; 4 a=10, b=20; 5 c= prnt(a,b); 6 System.out.printf("a=%d, b=%d, c=%d", a,b,c); 7 } 8 static int prnt(int x, int y){ 9 int z; 10 if(x==y) 11 z = x+y; 12 else 13 z = x-y; 14 return(z); 15 } 16 } 결과 a = 10 , b = 20, c = -10 설명 5열 : 정수형 a,b를 인수로 하여 prnt() 메소드를 호출한 결과를 c에 저장한다. 8열 : 실행 클래스 안에 메소드를 정의할 때 static 변수를 사용 - i.. 2020. 10. 20.
거꾸로 출력하기 1 public class Problem{ 2 public static void main(String[] args){ 3 String str = "Information!"; 4 int n = str.length(); 5 char[] st = new char(n); 6 n--; 7 for(int k=n; k>=0; k--){ 8 st[n-k] = str.charAt(k); 9 } 10 for(char c:st){ 11 System.out.printf("%c", c); 12 } 13 } 14 } 문자열은 String 전역 객체를 직접 사용하여 생성할 수 있습니다. 3열 : String str은 Information! 이라는 문자열을 저장 4열 : 문자열 변수 str의 크기인 12를 정수형 변수 n의 초기값으.. 2020. 10. 19.
연습 [ 1~100 ] 1~100까지 더하는 코드 작성법 [ * T스토리에 그대로 쓰는 것이기 때문에 Class 선언 등 기본 문은 없습니다. ] public static void main(String[] args) { int a = 1; // 변수에 a의 초깃값으로 1을 선언 int sum = 0; // 1~100까지 더한 값을 넣을 sum이라는 변수를 선언한 후 초깃값을 0으로 설정 for ( int i = 0; i < = 100; i ++ ) { // 반복문을 사용하여 처음 시작하는 값을 0, i가 100보다 같거나 클때까지 반복, i를 1씩 증가 sum += i; // 하나씩 반복한 i의 값을 sum에 저장한다. } System.out.println( " 1~100까지 더한 값은 : "" + sum ) ; } 1~100.. 2020. 4. 13.
반응형