"๊ฐ์ ํ: ๋ช
ํ JAVAESSENTIAL(ํฉ๊ธฐํ)"๊ต์ฌ์ ์๋ก๋ ๋ฌธ์ ๋ค์ ํ์ด์ ์ฌ๋ฆฝ๋๋ค. ๋ฌธ์ ์ ๋ฒํธ๋ง ํ๊ธฐํ๊ณ ๋ต์๋ง ์ ๋ ํํ๋ก ์ ๋ก๋ ํ๊ณ ์์ต๋๋ค. ๊ฐ์ธ ํ์ด์ด๋ฏ๋ก ์ค๋ต์ด ์์ ์ ์์ผ๋ฉฐ ์ค๋ต ๋ฐ๊ฒฌ ์ ๋๊ธ ๋จ๊ฒจ์ฃผ์๋ฉด ๊ฐ์ฌํ๊ฒ ์ต๋๋ค๐ - #์ด ํ์๋ ๊ฑด ์์ง ํ์ง ๋ชปํ ๋ฌธ์ or ํท๊ฐ๋ฆฌ๋ ๋ฌธ์ ์ ๋๋ค! ์ถํ์ ๋ค์ ํ์ด์ ์ฌ๋ฆด ์์ ์ด์์! -ujeyhx- |
๐์ค์ต๋ฌธ์
1)
import java.util.Scanner;
public class TEST {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("์ํ๋ฒณ ํ ๋ฌธ์๋ฅผ ์
๋ ฅํ์ธ์ >>");
String s = sc.next(); //๋ฌธ์์ด๋ก ์ฝ์
char c = s.charAt(0); // ๋ฌธ์์ด์ ์ฒซ ๋ฒ์งธ ๋ฌธ์
for (int i='a'; i<=c; i++) { // a๋ถํฐ c๊น์ง ๊ฐ ์ฆ๊ฐ
for (int k=i; k<=c; k++) { // i๋ถํฐ c๊น์ง
System.out.print((char)(k)); //์ถ๋ ฅ i๊ฐ ์ฆ๊ฐํ๋ฏ๋ก ๋ง์ง๋ง์ผ๋ก c์ถ๋ ฅ ํ ๋ง๋ฌด๋ฆฌ
}
System.out.println();
}
sc.close();
}
}
2)
import java.util.Scanner;
public class TEST {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num[] = new int[10];
System.out.print("์ ์ 10๊ฐ ์
๋ ฅ >>");
for (int i=0; i<num.length; i++) {
num[i] = sc.nextInt();
}
for (int i=0; i<num.length; i++) {
if (num[i] % 3 == 0 ) {
System.out.print(num[i]+" ");
}
}
sc.close();
}
}
3)
import java.util.InputMismatchException;
import java.util.Scanner;
public class TEST {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("์ ์๋ฅผ ์
๋ ฅํ์ธ์ >>");
int num;
try {
num = sc.nextInt();
if (num % 2 == 0) {
System.out.print("์ง์");
}
else {
System.out.print("ํ์");
}
}
catch(InputMismatchException e) {
System.out.println("์๋ฅผ ์
๋ ฅํ์ง ์์ ์ข
๋ฃํฉ๋๋ค.");
}
sc.close();
}
}
4)
import java.util.InputMismatchException;
import java.util.Scanner;
public class TEST {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
char day[] = {'์ผ','์','ํ','์','๋ชฉ','๊ธ','ํ '};//0~6
int num,index=0;
while (true) {
System.out.print("์ ์๋ฅผ ์
๋ ฅํ์ธ์ >>");
try {
num = sc.nextInt();
if (num < 0) {
System.out.print("ํ๋ก๊ทธ๋จ ์ข
๋ฃํฉ๋๋ค...");
break;
}
index = num%7;
System.out.println(day[index]);
}
catch(InputMismatchException e) {
System.out.println("๊ฒฝ๊ณ ! ์๋ฅผ ์
๋ ฅํ์ง ์์์ต๋๋ค.");
sc.nextLine();
}
}
sc.close();
}
}
# 5)
import java.util.Scanner;
public class TEST {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int array[] = new int[10]; //0~9
int temp=0;
System.out.print("์ ์ 10๊ฐ ์
๋ ฅ>>");
for (int i=0; i<array.length; i++) {
array[i] = sc.nextInt();
}
for (int i=0; i<array.length; i++) {
for(int j = 0; j < array.length-i-1; j++) {
if(array[j] > array[j+1]) {
temp = array[j];
array[j] = array[j+1];
array[j+1] = temp;
}
}
}
for (int i=0; i<array.length; i++) {
System.out.print(array[i]+ " ");
}
sc.close();
}
}
6)
import java.util.Scanner;
public class TEST {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String eng[] = {"student","love","java","happy","future"};
String kor[] = {"ํ์","์ฌ๋","์๋ฐ","ํ๋ณตํ","๋ฏธ๋"};
String input;
while (true) {
System.out.print("์์ด๋จ์ด๋ฅผ ์
๋ ฅํ์ธ์ >>");
input = sc.nextLine();
for (int i=0; i<eng.length; i++) {
if (eng[i].equals(input)) {
System.out.println(kor[i]);
break;
}
else if(!eng[i].equals(input)&&i==eng.length-1) {
System.out.println("๊ทธ๋ฐ ์์ด๋จ์ด ์์ด์ ");
break;
}
}
if(input.equals("exit")) {
System.out.print("์ข
๋ฃํฉ๋๋ค...");
break;
}
}
sc.close();
}
}
7)
public class TEST {
public static void main(String[] args) {
int i;
for (i=1; i<100; i++) {
int first = i/10;
int second = i%10;
int clap = 0;
if (first != 0 && first % 3 == 0)
clap =1;
if (second != 0 && second % 3 == 0)
clap =1;
if (first == 3 && second == 3)
clap =2;
if (clap == 1)
System.out.println(i + " ๋ฐ์ ํ๋ฒ");
else if (clap == 2)
System.out.println(i + " ๋ฐ์ ๋๋ฒ");
}
}
}
8)
import java.util.InputMismatchException;
import java.util.Scanner;
public class TEST {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str[] = {"๊ฐ์","๋ฐ์","๋ณด"};
while (true) {
System.out.println("** ์ปดํจํฐ์ ๊ฐ์ ๋ฐ์ ๋ณด ๊ฒ์์ ์์ํ ๊ฒ์ **");
System.out.print("๊ฐ์ ๋ฐ์ ๋ณด !>>");
String input = sc.nextLine();
int n = (int)(Math.random()*3);
if(input.equals("๊ทธ๋ง")) {
System.out.print("๊ฒ์์ ์ข
๋ฃํฉ๋๋ค...");
break;
}
System.out.print("์ฌ์ฉ์=>" + input);
System.out.print(" ์ปดํจํฐ=>" + str[n]);
if(str[n].equals("๊ฐ์")) {
if(input.equals("๊ฐ์"))
System.out.println("/ ๋น๊ฒผ์ต๋๋ค");
if(input.equals("๋ฐ์"))
System.out.println("/ ์ฌ์ฉ์๊ฐ ์ด๊ฒผ์ต๋๋ค");
if(input.equals("๋ณด"))
System.out.println("/ ์ปดํจํฐ๊ฐ ์ด๊ฒผ์ต๋๋ค");
}
if(str[n].equals("๋ฐ์")) {
if(input.equals("๊ฐ์"))
System.out.println("/ ์ปดํจํฐ๊ฐ ์ด๊ฒผ์ต๋๋ค");
if(input.equals("๋ฐ์"))
System.out.println("/ ๋น๊ฒผ์ต๋๋ค");
if(input.equals("๋ณด"))
System.out.println("/ ์ฌ์ฉ์๊ฐ ์ด๊ฒผ์ต๋๋ค");
}
if(str[n].equals("๋ณด")) {
if(input.equals("๊ฐ์"))
System.out.println("/ ์ฌ์ฉ์๊ฐ ์ด๊ฒผ์ต๋๋ค");
if(input.equals("๋ฐ์"))
System.out.println("/ ์ปดํจํฐ๊ฐ ์ด๊ฒผ์ต๋๋ค");
if(input.equals("๋ณด"))
System.out.println("/ ๋น๊ฒผ์ต๋๋ค");
}
}
sc.close();
}
}
Bonus 1)
public class TEST {
public static void main(String[] args) {
int intArray[][];
intArray = new int[3][4];
for(int i=0; i<3; i++) {
for(int j=0; j<4; j++) {
intArray[i][j] = (int)(Math.random()*10);
}
}
for(int i=0; i<intArray.length; i++) {
for(int j=0; j<intArray[i].length; j++) {
System.out.print(intArray[i][j]+ " ");
}
System.out.println();
}
int i=0, sum=0;
for(i=0; i<intArray.length; i++) { //3
for(int j=0; j<intArray[i].length; j++) { //4
sum += intArray[i][j];
}
}
System.out.println("ํฉ์ " + sum);
}
}