archive
[5주차 실습] 3월 30일 Problem Set 본문
1. We want to manage the scores of 5 students. If the inputs are the name and Korean, English, and mathematics scores for each student, we want to print the two-dimensional table including not only the name and all scores but also the sum and the average for each student adding the two columns. Then we want to add two rows to represent the sum and the average for each subject.
Console Input: The name, Korean score, English score, mathematics score for 5 students.
Console Output:
package March30;
import java.util.Scanner;
public class Project01 {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("The name, Korean score, English score, mathematics score for 5 students.");
Scanner input = new Scanner(System.in);
String names[]=new String[7];
int chart[][]=new int[7][5];
int krsum=0;
int mathsum=0;
int engsum=0;
System.out.println("5 names input >>> ");
for(int i=0;i<5;i++) {
String name;
name=input.next();
names[i]=name;
}
names[5]="Sum";
names[6]="Mean";
System.out.println("5 Korean score input >>> ");
for(int i=0;i<5;i++) {
int krscore;
krscore=input.nextInt();
chart[i][0]=krscore;
krsum+=krscore;
}
chart[5][0]=krsum;
chart[6][0]=krsum/5;
System.out.println("5 English score input >>> ");
for(int i=0;i<5;i++) {
int engscore;
engscore=input.nextInt();
chart[i][1]=engscore;
engsum+=engscore;
}
chart[5][1]=engsum;
chart[6][1]=engsum/5;
System.out.println("5 Mathematics score input >>> ");
for(int i=0;i<5;i++) {
int mascore;
mascore=input.nextInt();
chart[i][2]=mascore;
mathsum+=mascore;
}
chart[5][2]=mathsum;
chart[6][2]=mathsum/5;
int indsum = 0;
for(int i=0;i<5;i++) {
for(int j=0;j<3;j++) {
indsum+=chart[i][j];
chart[i][3]=indsum;
}
chart[i][4]=indsum/3;
indsum = 0;
}
System.out.println("Name Korean English Math Sum Mean\n");
for(int i=0; i<7;i++) {
System.out.print(names[i]);
for(int j=0; j<5;j++)
System.out.printf(" %5d", chart[i][j]);
System.out.println("");
}
}
}
2. After receiving the positive integer n, print the pyramid as follows.
Console Input: The number n (ex. 5)
Console Output: The following diagram
package March30;
import java.util.Scanner;
public class Project02 {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("The number >>>");
Scanner input = new Scanner(System.in);
int num=input.nextInt();
for (int row = 0 ; row < num ; row++) {
for (int col = num ; col >= 0 ; col--) { // 왼쪽을 출력하는 for문
if (row >= col) {
System.out.print(col);
} else {
System.out.print(" ");
}
}
for (int col = 1 ; col <= num ; col++) { // 오른쪽을 출력하는 for문
if (row >= col) {
System.out.print(col);
} else {
System.out.print(" ");
}
}
System.out.println(); // 줄넘김
}
}
'Java > 23_1 소프트웨어프로젝트' 카테고리의 다른 글
[9주차 실습] 4월 28일 Problem Set (0) | 2023.04.28 |
---|---|
[7주차 실습] 4월 13일 Problem Set (0) | 2023.04.28 |
[6주차 실습] 4월 6일 Problem Set (0) | 2023.04.06 |
[4주차 실습] 3월 23일 Problem Set (0) | 2023.03.30 |
[3주차 실습] 3월 14일 Problem Set (0) | 2023.03.18 |