Java7_2
8893 ワード
package pack_Conversion;
public class Ref {
private int ins;
private String code;
public Ref(int ins, String code) { //생성자 기능 필드 초기화
this.ins = ins;
this.code = code;
if(code.equals("1")) {
mtdConvsKtM();
} else if (code.equals("2")) {
mtdConvsMtK();
}
}
public void mtdConvsKtM() {
double res = ins * 0.621;
System.out.printf("%d km = %.2f mile", ins, res );
}
public void mtdConvsMtK() {
double res = ins / 0.621;
System.out.printf("%d mile = %.2f km", ins, res );
}
}
package pack_Conversion;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("입력 선택(1.킬로미터 2. 마일) : ");
String code = sc.nextLine();
String unitTxt = null;
switch(code){
case "1":
unitTxt = "킬로미터 입력(km) : ";
break;
case "2":
unitTxt = "마일 입력(mile) : ";
break;
}
System.out.print(unitTxt);
int ins = sc.nextInt();
sc.close();
Ref ref = new Ref(ins, code);
//ref.mtdConversion();
}
}
Reference
この問題について(Java7_2), 我々は、より多くの情報をここで見つけました https://velog.io/@goeune/Java72テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol