목차
1. 7장 내용점검
2. 7장 프로그래밍 연습
2. 7장 프로그래밍 연습
본문내용
VALUE);
System.out.println("\t\t 최대값: " + Character.MAX_VALUE);
}
}
3. 20개의 수(0에서 9까지의 정수)를 입력 받아 그 빈도 수가 가장 많은 수와 빈도 수를
출력하는 프로그램을 작성하시오.
import java.util.Scanner;
public class no3 {
public static void main(String[] args) {
int max=0;
int[] num = new int[20];
int[] count = new int[20];
Scanner s = new Scanner(System.in);
System.out.print("0에서 9까지의 정수 20개를 입력하시오: ");
for(int i=0; i
num[i] = s.nextInt();
}
s.close();
for(int i=0; i
int n=0;
for(int j=0; j
if(num[i]==num[j]) n++;
}
count[i]=n;
for(int k=0; k
if(count[i]>count[k]) max=i;
}
}
System.out.println("빈도수가 가장 많은 수: " + num[max]);
System.out.println("그 숫자의 빈도 횟수: " + count[max]);
}
}
4. 다음 표의 가로 합과 세로 합, 그리고 모든 수의 합을 구하는 프로그램을 작성하시오.
public class no4 {
public static void main(String[] args) {
int array[][] = {{35, 28, 67, 73}, {25, 32, 12, 69},
{97, 56, 14, 23}, {45, 97, 48, 15}};
int totalSum=0;
for(int i=0; i
int widthSum=0, heightSum=0;
for(int j=0; j
widthSum += array[i][j];
heightSum += array[j][i];
}
System.out.print((i+1) + "n번째 가로의 합: " + widthSum);
System.out.println("\t세로의 합: " + heightSum);
totalSum += widthSum;
}
System.out.println("\n모든 수의 합: " + totalSum);
}
}
5. 다음 3*3의 두 배열에서, 같은 첨자의 행과 열에 대응하는 원소의 합과 차를 구하는
(행렬의 합과 차를 구하는) 프로그램을 작성하시오.
public class no5 {
public static void main(String[] args) {
int[][] array1 = {{35, 28, 73}, {25, 32, 69}, {97, 56, 23}, {45,97,15}};
int[][] array2 = {{125, 28, 56}, {32, 32, 69}, {57, 56, 59}, {45, 33, 45}};
int[][] sum = new int[array1.length][array1[0].length];
int[][] blance = new int[array2.length][array2[0].length];
System.out.println("\t<<행렬의 합과 차를 구하는 프로그램>>\n");
for(int i=0; i
for(int j=0; j
sum[i][j] = array1[i][j] + array2[i][j];
System.out.print("\t행렬의 합[" + (i+1) + "][" + (j+1)
+ "]= " + sum[i][j]);
}
System.out.println();
}
System.out.println();
for(int i=0; i
for(int j=0; j
blance[i][j] = array1[i][j] - array2[i][j];
System.out.print("\t행렬의 차[" + (i+1) + "][" + (j+1)
+ "]= " + blance[i][j]);
}
System.out.println();
}
}
}
6. 예제 프로그램 SelectionSort를 수정하여 표준 입력으로 n개의 자료를 입력 받아
정렬의 결과를 출력하는 프로그램을 작성하시오.
import java.util.Scanner;
public class no6 {
public static void main(String[] args) {
int input[] = new int[10];
Scanner s = new Scanner(System.in);
System.out.println("\t<<입력된 정수를 작은 것 부터 정렬하는 프로그램>>\n");
System.out.print("입력할 자료(저웃) 갯수 입력: ");
int n = s.nextInt();
System.out.print("위에서 입력한 갯수만큼 정수 입력: ");
for(int i=0; i
input[i] = s.nextInt();
}
s.close();
int start=0;
while(start
int minIndex = start;
for(int i=start+1; i
if(input[minIndex] > input[i]) {
minIndex = i;
}
}
if(minIndex != start) {
int dummy;
dummy = input[start];
input[start] = input[minIndex];
input[minIndex] = dummy;
}
start++;
}
System.out.print("정렬의 결과는 ==> ");
for(int i=0; i
System.out.print(input[i] + " ");
}
}
}
System.out.println("\t\t 최대값: " + Character.MAX_VALUE);
}
}
3. 20개의 수(0에서 9까지의 정수)를 입력 받아 그 빈도 수가 가장 많은 수와 빈도 수를
출력하는 프로그램을 작성하시오.
import java.util.Scanner;
public class no3 {
public static void main(String[] args) {
int max=0;
int[] num = new int[20];
int[] count = new int[20];
Scanner s = new Scanner(System.in);
System.out.print("0에서 9까지의 정수 20개를 입력하시오: ");
for(int i=0; i
}
s.close();
for(int i=0; i
for(int j=0; j
}
count[i]=n;
for(int k=0; k
}
}
System.out.println("빈도수가 가장 많은 수: " + num[max]);
System.out.println("그 숫자의 빈도 횟수: " + count[max]);
}
}
4. 다음 표의 가로 합과 세로 합, 그리고 모든 수의 합을 구하는 프로그램을 작성하시오.
public class no4 {
public static void main(String[] args) {
int array[][] = {{35, 28, 67, 73}, {25, 32, 12, 69},
{97, 56, 14, 23}, {45, 97, 48, 15}};
int totalSum=0;
for(int i=0; i
for(int j=0; j
heightSum += array[j][i];
}
System.out.print((i+1) + "n번째 가로의 합: " + widthSum);
System.out.println("\t세로의 합: " + heightSum);
totalSum += widthSum;
}
System.out.println("\n모든 수의 합: " + totalSum);
}
}
5. 다음 3*3의 두 배열에서, 같은 첨자의 행과 열에 대응하는 원소의 합과 차를 구하는
(행렬의 합과 차를 구하는) 프로그램을 작성하시오.
public class no5 {
public static void main(String[] args) {
int[][] array1 = {{35, 28, 73}, {25, 32, 69}, {97, 56, 23}, {45,97,15}};
int[][] array2 = {{125, 28, 56}, {32, 32, 69}, {57, 56, 59}, {45, 33, 45}};
int[][] sum = new int[array1.length][array1[0].length];
int[][] blance = new int[array2.length][array2[0].length];
System.out.println("\t<<행렬의 합과 차를 구하는 프로그램>>\n");
for(int i=0; i
System.out.print("\t행렬의 합[" + (i+1) + "][" + (j+1)
+ "]= " + sum[i][j]);
}
System.out.println();
}
System.out.println();
for(int i=0; i
System.out.print("\t행렬의 차[" + (i+1) + "][" + (j+1)
+ "]= " + blance[i][j]);
}
System.out.println();
}
}
}
6. 예제 프로그램 SelectionSort를 수정하여 표준 입력으로 n개의 자료를 입력 받아
정렬의 결과를 출력하는 프로그램을 작성하시오.
import java.util.Scanner;
public class no6 {
public static void main(String[] args) {
int input[] = new int[10];
Scanner s = new Scanner(System.in);
System.out.println("\t<<입력된 정수를 작은 것 부터 정렬하는 프로그램>>\n");
System.out.print("입력할 자료(저웃) 갯수 입력: ");
int n = s.nextInt();
System.out.print("위에서 입력한 갯수만큼 정수 입력: ");
for(int i=0; i
}
s.close();
int start=0;
while(start
for(int i=start+1; i
minIndex = i;
}
}
if(minIndex != start) {
int dummy;
dummy = input[start];
input[start] = input[minIndex];
input[minIndex] = dummy;
}
start++;
}
System.out.print("정렬의 결과는 ==> ");
for(int i=0; i
}
}
}
키워드
추천자료
- [상업교육]일본의 상업교육
- 열혈강의 C언어 재정리 및 문제 풀이#2
- 문화와 사회 토론 보고서
- 데이터베이스시스템 5판 복습문제 풀이(1장 ~ 14장) - Ramez A. Elmasri 저, 황규영 역
- [정보체계론] 정보체계론 요점정리 서브노트
- 2009년 2학기 컴퓨터구조 기말시험 핵심체크
- html로 시간표 만드는 소스
- 2011년 2학기 컴퓨터구조 기말시험 핵심체크
- 레고 마인드스톰 공 수집 로봇 프로젝트 제안서
- 2012년 하계계절시험 컴퓨터구조 시험범위 핵심체크
- 컴퓨터구조 교재전범위 핵심요약노트
- 명쾌한 이공계 글쓰기 줄거리 요약 및 감상문, 느낀점, 독후감, 나의 견해, 나의 소감, 조사분석
- 2012년 2학기 컴퓨터구조 기말시험 핵심체크
- 2013년 2학기 컴퓨터구조 기말시험 핵심체크