๋ด๊ฐ ์ข์ํ๋ ์๋ฆฌ ์ ๋ชฉ์ ์ ๋ ฅํ๊ณ ๊ดํธ๋ก ๊ฐ์ธ์ ์ถ๋ ฅ
์ฒ์ ์๋ฆฌ ์ ๋ชฉ์ ๋ฌธ์์ด๋ก ์
๋ ฅ๊ฐ์ ์ฃผ๊ณ ์ถ๋ ฅํ๋๋ฐ ๊ณ์ ์ค๋ฅ๊ฐ ๋ด๋ค. ๋ถ๋ช
๋ฌธ์์ด๋ ์ฐธ์กฐํ ๋ณ์๋ผ ํ๋๋ฐ,, ๋ฐฐ์ด๋ก ํด์ผํ๋ ์ถ์ด์ Array toString๋ ํด๋ณด๊ณ ๋ณ์ ์ด๋ฆ๋ ๋ฐ๊ฟ๋ณด๊ณ ํ๋๋ฐ ์๋๋๊ฑฐ๋ค!! ์๊ณ ๋ณด๋ string์ ์๋ฌธ์๋ก ์
๋ ฅํด์ ์๋๋ ๊ฑฐ์๋ค,,, String ๋๋ฌธ์ ๊ธฐ์ตํ์~
public class Main {
public static void main(String[] args) {
String title = "๋ฐฑ์ข
์ ๋ผ์ง๊ณ ๊ธฐ ๊น์น์ฐ๊ฐ ๋ง๋ค๊ธฐ";
System.out.println("[ " + title + " ]");
}
}
์๋ฆฌ ๋ณ์ ์ 1~5 ์ฌ์ด์ ์์์ ์ด ์๋ ์ค์๋ก ์ ๋ ฅํ๊ณ ์์์ ์ ์ ์ธํ ์ ์๋ก๋ง ์ถ๋ ฅ
์ด๊ฑด ์ค์ํ์ ์ ์ํ์ผ๋ก ํ๋ณํ์ ํ๋ผ๋ ๊ฒ ๊ฐ๋ค. ํ์ต์๋ฃ ๋ณด๊ณ ์ฐธ๊ณ ํ๋ฉด์ ํ๋๋ ์ด๊ฑด ํ๋ฒ์ ์ฑ๊ณตํ๋ค.
public class Main {
public static void main(String[] args) {
String title = "๋ฐฑ์ข
์ ๋ผ์ง๊ณ ๊ธฐ ๊น์น์ฐ๊ฐ ๋ง๋ค๊ธฐ";
double doubleScore = 3.5;
int intScore;
intScore = (int) doubleScore;
System.out.println("[ " + title + " ]");
System.out.println(intScore);
}
}
๋ฐ๋ก ๋ค์ ์ ์ ๋ณ์ ์ 5์ ๋ง์ ํผ์ผํธ๋ก ํํํ์ ๋ ๊ฐ์ ์ค์๋ก ์ถ๋ ฅ
์ด๊ฒ ๋ง๋..? ์ถ์ง๋ง ์ผ๋จ ๊ฒฐ๊ณผ๋ ๋ง๊ฒ ๋์จ๋ค!
public class Main {
public static void main(String[] args) {
String title = "๋ฐฑ์ข
์ ๋ผ์ง๊ณ ๊ธฐ ๊น์น์ฐ๊ฐ ๋ง๋ค๊ธฐ";
double doubleScore = 3.5;
double percent = 60.0;
int intScore;
intScore = (int) doubleScore;
System.out.println("[ " + title + " ]");
System.out.println("๋ณ์ : " + intScore + " (" + percent + "%)");
}
}
์๋ฆฌ ๋ ์ํผ 10๋ฌธ์ฅ์ ์ ๋ ฅ ํ ๋ชจ๋ ๋ฌธ์ฅ ์์ ๋ฒํธ๋ฅผ ๋ถ์ฌ์ ๋ชจ๋ ์ถ๋ ฅ
์ด๊ฒ๋ String ๋ฌธ์์ด๋ก ๋ณ์ ์ ๋ ฅ๋ฐ๊ณ ์ถ๋ ฅํ ๋ ์์ ๋ฒํธ๋ง ๋ถ์ฌ์ฃผ๋ฉด ๋๋ค.
public class Main {
public static void main(String[] args) {
String title = "๋ฐฑ์ข
์ ๋ผ์ง๊ณ ๊ธฐ ๊น์น์ฐ๊ฐ ๋ง๋ค๊ธฐ";
double doubleScore = 3.5;
double percent = 60.0; // ๋ฐฑ๋ถ์จ ๊ณ์ฐ intScore * 100 / 5;
int intScore;
intScore = (int) doubleScore;
String one = "๋ผ์ง๊ณ ๊ธฐ๋ ํ๋ฌผ์ ๋นผ์ฃผ์ธ์.";
String two = "์์ต์ ๊น์น ํํฌ๊ธฐ๋ฅผ ๊บผ๋ด์ ์๋ผ์ฃผ์ธ์.";
String three = "๋๋น์ ๋ค๊ธฐ๋ฆ ์ ๋นํ ๋๋ฅด๊ณ ๊น์น๋ฅผ ๋ฃ๊ณ ๋ณถ์์ฃผ์ธ์.";
String four = "๋ค์ง๋ง๋ ํ์คํผ, ์คํ ํ์คํผ ๋ฃ์ด์ฃผ์ธ์.";
String five = "์ข
์ด์ปต์ผ๋ก ๋ฌผ 8์ปต ๋ถ์ด์ ์ผ๋ถ์ ๋์ฌ์ฃผ์ธ์.";
String six = "ํ๋ฌผ ๋บ ๋ผ์ง๊ณ ๊ธฐ๋ฅผ ๋ฃ์ด์ฃผ์ธ์.";
String seven = "๋์ฅ ๋ฐ์คํผ, ์ํ ๋ฐ๊ฐ, ์ฒญ์๊ณ ์ถ ํ๊ฐ๋ฅผ ์ฐ์ด์ ๋ฃ์ด์ฃผ์ธ์.";
String eight = "๊ฐ์ฅ ๋์คํผ๋ฐ, ์์ฐ์ ๋์คํผ, ๊ณ ์ถง๊ฐ๋ฃจ ๋์คํผ๋ฐ ๋ฃ์ด์ฃผ์ธ์.";
String nine = "์ค๋ถ๋ก ์ค์ฌ์ ์ค๋ ๋์ฌ์ฃผ์ธ์.";
String ten = "๋ง์ง๋ง์ ํ ์ญ์ญ ์ฐ์ด์ ๋ง๋ฌด๋ฆฌํ๋ฉด ๋ผ์";
System.out.println("[ " + title + " ]");
System.out.println("๋ณ์ : " + intScore + " (" + percent + "%)");
System.out.println("1. " + one);
System.out.println("2. " + two);
System.out.println("3. " + three);
System.out.println("4. " + four);
System.out.println("5. " + five);
System.out.println("6. " + six);
System.out.println("7. " + seven);
System.out.println("8. " + eight);
System.out.println("9. " + nine);
System.out.println("10. " + ten);
}
}

์ด๋ฐ ์๋ฐ๊ฐ์... ๋ ๊ฐ์์์ ๋ฐฐ์ด๋๋ก ํ๋๋ฐ ์ ๋ต์ Scanner๋ฅผ ์ด์ฉํด์ ์
๋ ฅ๊ฐ์ ์ง์ ๋ฐ๋๊ฑฐ์๋ค,, (์์๋ ค์คฌ๋๋ฐ ์ด์ผํด์ใ
) ๋ฐฑ๋ถ์จ ๊ณ์ฐ ์ด๋ป๊ฒ ํ๋ ๊ฑฐ์ง ํ๋๋ฐ ์ ์ * 100 / 5 ์ด๊ฑฐ์๋ค.
import java.util.Scanner;
public class First_project {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String cookName = sc.nextLine();
String recipe1 = sc.nextLine();
String recipe2 = sc.nextLine();
String recipe3 = sc.nextLine();
String recipe4 = sc.nextLine();
String recipe5 = sc.nextLine();
String recipe6 = sc.nextLine();
String recipe7 = sc.nextLine();
String recipe8 = sc.nextLine();
String recipe9 = sc.nextLine();
String recipe10 = sc.nextLine();
float score = sc.nextFloat();
int scoreNumber = (int)score; // ๋ณ์ int ํ ๋ณํ
double percentage = scoreNumber * 100 / 5; // ํผ์ผํธ ๊ณ์ฐ
// ๊ฒฐ๊ณผ ์ถ๋ ฅ
System.out.println(score);
System.out.println("[ " + cookName + " ]");
System.out.println("๋ณ์ : " + scoreNumber + " (" + percentage + "%)");
System.out.println("1. " + recipe1);
System.out.println("2. " + recipe2);
System.out.println("3. " + recipe3);
System.out.println("4. " + recipe4);
System.out.println("5. " + recipe5);
System.out.println("6. " + recipe6);
System.out.println("7. " + recipe7);
System.out.println("8. " + recipe8);
System.out.println("9. " + recipe9);
System.out.println("10. " + recipe10);
}
}
Scannerํด๋์ค๋ ๋ค์ํ ์
๋ ฅ ์์ค๋ก๋ถํฐ ๋ฐ์ดํฐ๋ฅผ ์ฝ์ ์ ์๊ฒ ํด์ฃผ๋ ํธ๋ฆฌํ ๋๊ตฌ๋ผ๊ณ ํ๋ค.
Scanner sc = new Scanner(System.in); โ 'Scanner' ๊ฐ์ฒด๋ฅผ ์์ฑํ๊ณ , ์ฝ์ ์
๋ ฅ์ ์ฝ์ ์ค๋น