archive
[4주차 실습] 3월 23일 Problem Set 본문
1. Take no more than 10 integers and put them in an array, and compute the mean and variance of the integers.
package March23;
import java.util.*;
public class Project1 {
public static void main(String[] args) {
System.out.println("10개의 정수를 입력하세요 >>>");
int[] arr= new int[10];
int sum=0;
Scanner input=new Scanner(System.in);
for(int i=0;i<10;i++) {
int num=input.nextInt();
arr[i]=num;
sum+=arr[i];
}
double average=(double)sum/10;
System.out.printf("10개 정수의 평균은 >>> %f\n", average);
double sum2=0;
for(int i=0;i<10;i++) {
sum2+=(arr[i]-average)*(arr[i]-average);
}
double variance=(double)sum2/10;
System.out.printf("10개 정수의 분산은 >>> %f\n", variance);
}
}
2. Take five strings that is separated with commas, place each string in the array, check if each string has a string ”java” and print true/false, and if true, print out a string replaced with ”python”.
package March23;
import java.util.*;
public class Project2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("다섯 개의 문자열을 쉼표로 구분하여 입력하여라 >>> ");
Scanner input=new Scanner(System.in);
String original=input.nextLine();
String[] arr=original.split(",");
for(int i=0;i<arr.length;i++) {
if(arr[i].contains("java")) {
System.out.println("true");
String rep=arr[i].replace("java", "python");
System.out.println(rep);
}
else
System.out.println("false");
}
}
}
'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 |
[5주차 실습] 3월 30일 Problem Set (0) | 2023.03.31 |
[3주차 실습] 3월 14일 Problem Set (0) | 2023.03.18 |