Day_3 (2/18)
7826 ワード
前日宿題をする
1)
package basic;
import java.text.DecimalFormat;
public class PayTest {
結果
月給
基本給=25000,000ウォン
税金=82500ウォン
月給:2417500ウォン
2)大文字と小文字の変更
public class CompTest5 {
結果
k->K
public class Variable2 {
int a;//フィールド、インスタンス変数、初期化値=0
static int b;//フィールド、クラス変数、初期化
String c;
package method;
public class MethodTest {
こんにちは.
お会いできて嬉しいです.
最大値=36
最小値=20
public class MethodTest2 {
合=578
お茶
乗算
分
package basic;
import java.text.DecimalFormat;
public class PayTest {
/*
IO Stream(I/O) Console (System)
入力:システム.in
出力:システム.out
*/ package method;
import java.io.IOException;
public class InputTest {
/*
IO Stream(I/O)
入力:Reader
-BufferedReader
-FileReader
-InputStreamReader
出力:Writer
-BufferedWriter
-FileWriter
*/
package method;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class InputTest2 {
package method;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class SungJuk {
名前を入力:洪吉童
国語の点数を入力:95
英語のスコアを入力:78
数学点数の入力:56
洪吉童の
国語英語数学平均
95 78 56 229 76.333
/*10進数(dec)を入力し、2進数、8進数、16進数に変換してください.
(Integerクラスを使用する方法)
[結果]
10進数入力:250
バイナリ=111010
8進=372
16進=fa
*/
package method;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Jinsu {
さっきの単位問題にif単位を加える
/
単位の追加
平均値が90より大きい場合、A、80=B、70=C、60=D、60=F未満
/
package method;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class SungJuk {
1)
package basic;
import java.text.DecimalFormat;
public class PayTest {
public static void main(String[] args) {
char name = 'L';
int basePay = 2500000;
int tax = (int)(basePay * 0.033);
int salary = basePay - tax;
DecimalFormat df = new DecimalFormat("#,###");
System.out.println("*** " + name + "의 월급 ***");
System.out.println("기본급 = " + basePay + "원");
System.out.println("세금 = " + tax + "원");
System.out.println("월급 = " + df.format(salary) + "원");
}
}結果
月給
基本給=25000,000ウォン
税金=82500ウォン
月給:2417500ウォン
2)大文字と小文字の変更
public class CompTest5 {
public static void main(String[] args) {
char ch = 'k';
int result = ch>='A' && ch<='Z' ? ch+32 : ch-32; // 문자가 대문자이냐? 그럼 소문자로 아니면 대문자로 변경하라
System.out.println(ch + "->" + (char)result);
}
}結果
k->K
public class Variable2 {
int a;//フィールド、インスタンス変数、初期化値=0
static int b;//フィールド、クラス変数、初期化
String c;
public static void main(String[] args) {
int a=10; // 10 없이는 local variable(로컬변수), garbage(쓰레기 값)
System.out.println("local a = " + a);
Variable2 v;
v= new Variable2();
System.out.println("객체 v = " + v); //클래스@16진수
System.out.println("필드 a = " + v.a);
System.out.println("필드 b = " + b);
System.out.println("필드 c = " + new Variable2().c); //그냥 v라고 써도 된다
}
}package method;
public class MethodTest {
public static void main(String[] args) { //구현
disp();//호출
MethodTest mt;
mt = new MethodTest(); //호출
mt.output();
System.out.println("최대값 = " + max(25,36));
System.out.println("최소값 = " + mt.min(20,58));
}
public static void disp() {//구현
System.out.println("안녕하세요");
}
public void output() {
System.out.println("반갑습니다");
}
public static int max(int a, int b){
return a >= b ? a : b;
}
public int min(int a, int b){
return a < b ? a : b;
}
}こんにちは.
お会いできて嬉しいです.
最大値=36
最小値=20
public class MethodTest2 {
public static void main(String[] args) {
MethodTest2 mt2= new MethodTest2();
System.out.println("합 = " + mt2.sum(320, 258));
System.out.println("차 = " + mt2.sub(320, 258));
System.out.println("곱 = " + mt2.mul(320, 258));
System.out.println("몫 = " + mt2.div(320, 258));
}
public int sum(int a, int b) {
return a+b;
}
public int sub(int a, int b) {
return a-b;
}
public int mul(int a, int b) {
return a*b;
}
public String div(int a, int b) {
return String.format("%.2f", (double)a/b);
}
}合=578
お茶
乗算
分
package basic;
import java.text.DecimalFormat;
public class PayTest {
public static void main(String[] args) {
char name = 'L';
int basePay = 2500000;
int tax = (int)(basePay * 0.033);
int salary = basePay - tax;
DecimalFormat df = new DecimalFormat("#,###");
System.out.println("*** " + name + "의 월급 ***");
System.out.println("기본급 = " + basePay + "원");
System.out.println("세금 = " + tax + "원");
System.out.println("월급 = " + df.format(salary) + "원");
}
}/*
IO Stream(I/O)
入力:システム.in
出力:システム.out
*/
import java.io.IOException;
public class InputTest {
public static void main(String[] args) throws IOException {
System.out.print("데이터: ");
int a = System.in.read(); //1개의 문자만 받는다
System.out.println("결과 = " + a);
}
}/*
IO Stream(I/O)
入力:Reader
-BufferedReader
-FileReader
-InputStreamReader
出力:Writer
-BufferedWriter
-FileWriter
*/
package method;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class InputTest2 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int a;
double b;
System.out.print("정수를 입력하시오");
a = Integer.parseInt(br.readLine());//엔터를 칠때까지를 한줄로 본다, 문자열
System.out.print("실수를 입력하시오");
b = Double.parseDouble(br.readLine());
System.out.println(a + " + " + b + " = " + (a + b));
}
}package method;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class SungJuk {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("이름 입력 : ");
String name = br.readLine();
System.out.print("국어 점수 입력 : ");
int kor = Integer.parseInt(br.readLine());
System.out.print("영어 점수 입력 : ");
int eng = Integer.parseInt(br.readLine());
System.out.print("수학 점수 입력 : ");
int math = Integer.parseInt(br.readLine());
int tol = kor+eng+math;
double avg = (double)tol/3;
System.out.println("\t*** " + name + "성적 ***");
System.out.println("국어\t영어\t수학\t평균");
System.out.println(kor+"\t"+eng+"\t"+math+"\t"+tol+"\t"+String.format("%.3f",avg));
}
}名前を入力:洪吉童
国語の点数を入力:95
英語のスコアを入力:78
数学点数の入力:56
洪吉童の
国語英語数学平均
95 78 56 229 76.333
/*10進数(dec)を入力し、2進数、8進数、16進数に変換してください.
(Integerクラスを使用する方法)
[結果]
10進数入力:250
バイナリ=111010
8進=372
16進=fa
*/
package method;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Jinsu {
public static void main(String[] args) throws IOExc250eption {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("10진수 입력 : ");
int dec = Integer.parseInt(br.readLine());
String binary = Integer.toBinaryString(dec);
String octal = Integer.toOctalString(dec);
String hexa = Integer.toHexString(dec);
System.out.println("2진수 = " + binary);
System.out.println("8진수 = " + octal);
System.out.println("16진수 = " + hexa);
}
}さっきの単位問題にif単位を加える
/
単位の追加
平均値が90より大きい場合、A、80=B、70=C、60=D、60=F未満
/
package method;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class SungJuk {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("이름 입력 : ");
String name = br.readLine();
System.out.print("국어 점수 입력 : ");
int kor = Integer.parseInt(br.readLine());
System.out.print("영어 점수 입력 : ");
int eng = Integer.parseInt(br.readLine());
System.out.print("수학 점수 입력 : ");
int math = Integer.parseInt(br.readLine());
int tol = kor+eng+math;
double avg = (double)tol/3;
String grade = null;
if(avg>=90) grade = "A";
else if(avg<90 && avg>=80) grade = "B";
else if(avg<80 && avg>=70) grade = "C";
else if(avg<70 && avg>=60) grade = "D";
else grade = "F";
System.out.println("\t*** " + name + "성적 ***");
System.out.println("국어\t영어\t수학\t총점\t평균\t학점");
System.out.println(kor+"\t"+eng+"\t"+math+"\t"+tol+"\t"+String.format("%.3f",avg)+"\t"+grade);
}
}Reference
この問題について(Day_3 (2/18)), 我々は、より多くの情報をここで見つけました https://velog.io/@minpark_123/Day3-218テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol