본문 바로가기

자바/문법

난수(무작위 수) 출력 프로그램 예제) import java.util.Random;import java.util. Arrays; public class Test7 {public static void main(String[] args) {// Random은 난수를 구한다.Random rd=new Random();int n; for(int i=1; i 더보기
성적표 출력하는 프로그램 예제) import java.io.IOException;import java.io.BufferedReader;import java.io.InputStreamReader; // 성적처리 프로그램public class Test5 {public static void main(String[] args) throws IOException{BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int inwon;String name[];int score[][];int tot[], rank[]; do{System.out.print("처리할 인원수 ? ");inwon=Integer.parseInt(br.readLine());}while(inwon.. 더보기
입력된 여러 숫자를 작은 순서대로 정리하는 프로그램 예제) public class Test5 {public static void main(String[] args) {int[] a={56, 2, 34, 13, 17}; System.out.print("source data : ");for(int n : a)System.out.print(n+" ");System.out.println(); //selection sort (정렬)int temp;for(int i=0; i 더보기
배열을 이용한 요일 계산기 예제) import java.io.IOException;import java.io.InputStreamReader;import java.io.BufferedReader; public class Test4 {public static void main(String[] args) throws IOException {BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int []month={31,28,31,30,31,30,31,31,30,31,30,31};int y,m,d,w,total; do{System.out.print("년도 ? ");y=Integer.parseInt(br.readLine());}while(y 더보기
배열을 사용한 달력만들기 예제) import java.io.IOException;import java.io.InputStreamReader;import java.io.BufferedReader; public class Test3 {public static void main(String[] args) throws IOException {BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); //년도가 4의 배수이고 100의 배수가 아니거나 400배수이면 2월 29일// 서기 1년 1월 1일은 월요일입니다. int []month={31,28,31,30,31,30,31,31,30,31,30,31};int y,m,w,total; do{System.out.print.. 더보기
배열 사용방법과 향상된 for문 예제1) 배열의 사용 방법 public class Test1{public static void main(String[] args){int []a; //배열 선언 -> 이런식은 문번8번과 같이 메모리 할당해서 사용한다. -> 그리고 배열사용int []b=new int[5]; //선언과 동시에 메모리 할당 -> (문번13)배열 사용으로 넘어간다.int c[]=new int[]{10,20,30,40,50}; // 선언과 메모리 할당, 사용을 동시에 하는 식, int []c={10,20,30,40,50} 과 동일하다. // a[0]=10; -> 컴파일 오류. 메모리 할당을 하지 않았으므로. a=new int[5]; //메모리 할당 // a[5]=20; -> 런타임 오류. 첨자의 범위를 벗어나서. ->문번9 에서.. 더보기
return문 예제) import java.io.IOException; import java.io.InputStreamReader; import java.io.BufferedReader; public class Test11 { public static void main(String[] args) throws IOException { BufferedReader br=new BufferedReader( new InputStreamReader(System.in)); int n,s; System.out.print("수 ?"); n=Integer.parseInt(br.readLine()); if(n 더보기
label을 이용한 break문 예제) public class Test10 {public static void main(String[] args) {int n=0; gogo:while(true){System.out.println("밖깥 while 위");while(true){n++;if(n>=10) break gogo; if(n>=5) break; System.out.println(n);}System.out.println("바깥 while 아래");}System.out.println("프로그램 끝"); }} 결과) 바깥 while 위1234바깥 while 아래바깥 while 위바깥 while 아래바깥 while 위바깥 while 아래바깥 while 위바깥 while 아래바깥 while 위바깥 while 아래바깥 while 위프로그램 끝 더보기