"κ°μ ν: λͺ
ν JAVAESSENTIAL(ν©κΈ°ν)"κ΅μ¬μ μλ‘λ λ¬Έμ λ€μ νμ΄μ μ¬λ¦½λλ€. λ¬Έμ μ λ²νΈλ§ νκΈ°νκ³ λ΅μλ§ μ λ ννλ‘ μ λ‘λ νκ³ μμ΅λλ€. κ°μΈ νμ΄μ΄λ―λ‘ μ€λ΅μ΄ μμ μ μμΌλ©° μ€λ΅ λ°κ²¬ μ λκΈ λ¨κ²¨μ£Όμλ©΄ κ°μ¬νκ² μ΅λλ€π - #μ΄ νμλ 건 μμ§ νμ§ λͺ»ν λ¬Έμ or ν·κ°λ¦¬λ λ¬Έμ μ λλ€! μΆνμ λ€μ νμ΄μ μ¬λ¦΄ μμ μ΄μμ! -ujeyhx- |
πμ€μ΅λ¬Έμ
1)
import java.util.*;
public class TEST {
public static void main(String[] args) {
Vector<Double> v = new Vector<Double>();
Scanner sc = new Scanner(System.in);
for(int i=0; i<5; i++) {
double d = sc.nextDouble();
v.add(d);
}
double max = v.get(0);
for(int i=0; i<v.size(); i++) {
if(max < v.get(i))
max = v.get(i);
}
System.out.println("κ°μ₯ ν° μλ " + max);
sc.close();
}
}
2)
import java.util.*;
public class TEST {
public static void main(String[] args) {
ArrayList<Character> a = new ArrayList<Character>();
Scanner sc = new Scanner(System.in);
char c = 0;
System.out.print("λΉ μΉΈμΌλ‘ λΆλ¦¬νμ¬ 5κ°μ νμ μ
λ ₯ ABCDF >>");
for(int i=0; i<5; i++) {
c = sc.next().charAt(0);
a.add(c);
}
Iterator<Character> it = a.iterator();
while (it.hasNext()) {
char c1 = it.next();
switch(c1) {
case 'A' :
System.out.print("4.0 ");
break;
case 'B' :
System.out.print("3.0 ");
break;
case 'C' :
System.out.print("2.0 ");
break;
case 'D' :
System.out.print("1.0 ");
break;
case 'F' :
System.out.print("0.0 ");
break;
}
}
sc.close();
}
}
3)
import java.util.*;
public class TEST {
public static void main(String[] args) {
HashMap<String, Integer> dic = new HashMap<String, Integer>();
Scanner sc = new Scanner(System.in);
dic.put("μμ€νλ μ",2000);
dic.put("μλ©λ¦¬μΉ΄λ
Έ",2500);
dic.put("μΉ΄νΈμΉλ
Έ",3000);
dic.put("μΉ΄νλΌλΌ",3500);
System.out.println("μμ€νλ μ, μλ©λ¦¬μΉ΄λ
Έ, μΉ΄νΈμΉλ
Έ, μΉ΄νλΌλΌ μμ΅λλ€");
while(true) {
System.out.print("μ£Όλ¬Έ >>");
String str = sc.next();
if(str.equals("κ·Έλ§")) {
break;
}
int price = dic.get(str);
System.out.println(price);
}
sc.close();
}
}
4)
import java.util.*;
public class TEST {
public static void main(String[] args) {
Vector<Integer> v = new Vector<Integer>();
Scanner sc = new Scanner(System.in);
System.out.println("2000λ
λ λΆν° 2009λ
κΉμ§ 1λ
λ¨μλ‘ ν€ cm μ
λ ₯");
System.out.print(">>");
for(int i=0; i<10; i++) {
int n = sc.nextInt();
v.add(n);
}
int n =0;
int max = v.get(0);
for(int j=0; j<v.size(); j++) {
if(max < v.get(j)) {
max = v.get(j);
n = j;
}
}
System.out.println("κ°μ₯ ν€κ° λ§μ΄ μλ λ
λλ 200" + n + "λ
" + max + "cm");
sc.close();
}
}
5)
import java.util.*;
public class TEST {
public static void main(String[] args) {
HashMap<String, Integer> nations = new HashMap<String, Integer>();
Scanner sc = new Scanner(System.in);
System.out.println("λλΌ μ΄λ¦κ³Ό μΈκ΅¬λ₯Ό 5κ° μ
λ ₯νμΈμ");
String[] str = new String[5];
for(int i=0; i<5; i++) {
System.out.print("λλΌ μ΄λ¦, μΈκ΅¬>>");
String s = sc.next();
int n = sc.nextInt();
str[i] = s;
nations.put(s,n);
}
String n = null;
int max = nations.get(str[0]);
for(int j=0; j<nations.size(); j++) {
if(max < nations.get(str[j])) {
max = nations.get(str[j]);
n = str[j];
}
}
System.out.println("μ μΌ μΈκ΅¬κ° λ§μ λλΌλ (" + n + " , " + nations.get(n)+")");
sc.close();
}
}
6)
import java.util.*;
public class TEST {
public static void main(String[] args) {
HashMap<String, Integer> client = new HashMap<String, Integer>();
Scanner sc = new Scanner(System.in);
System.out.println("**ν¬μΈνΈ κ΄λ¦¬ νλ‘κ·Έλ¨μ
λλ€ **");
String[] str = new String[5];
int i = 0;
while (true) {
System.out.print("μ΄λ¦, ν¬μΈνΈ μ
λ ₯>>");
String s = sc.next();
if (s.equals("exit")) {
System.out.println("νλ‘κ·Έλ¨μ μ’
λ£ν©λλ€...");
break;
}
int n = sc.nextInt();
str[i] = s;
for (int j =0; j<i; j++) {
if (s.equals(str[j])) {
n += client.get(s);
client.put(s,n);
i--;
}
}
client.put(s,n);
for (int j =0; j<=i; j++) {
System.out.printf("( %s , %d )", str[j], client.get(str[j]));
}
System.out.println();
i++;
}
sc.close();
}
}
7)
import java.util.*;
class Location {
private int x, y;
public Location(int x, int y) {
this.x = x; this.y = y;
}
public double distance(Location b) {
double d = (x - b.x)*(x - b.x) + (y - b.y)*(y - b.y);
return Math.sqrt(d);
}
}
public class TEST {
public static void main(String[] args) {
ArrayList<Location> travel = new ArrayList<Location>();
Scanner sc = new Scanner(System.in);
travel.add(new Location(0,0)); // μμ μμΉ
System.out.println("μ₯κ° μ΄λν μμΉ(x,y)λ₯Ό 5κ° μ
λ ₯νλΌ.");
for (int i=0; i<5; i++) {
System.out.print(">> ");
int x = sc.nextInt();
int y = sc.nextInt();
travel.add(new Location(x, y));
}
travel.add(new Location(0,0)); // μ΅μ’
μμΉ
double sum = 0.0;
for(int i=0; i<travel.size()-1; i++) {
double d = travel.get(i).distance(travel.get(i+1));
sum += d;
}
System.out.println("μ΄ μ΄λ 거리λ " + sum);
sc.close();
}
}
bonus1)
import java.util.*;
public class TEST {
public static Vector<String> hashToVector(HashMap<String, String> h) {
Vector<String> v = new Vector<String>(); // λ²‘ν° μμ±
Set<String> s = h.keySet(); // ν΄μ맡 hλ‘λΆν° ν€μ Set 컬λ μ
s μ»κΈ°
Iterator<String> it = s.iterator();
while(it.hasNext()) {
String key = it.next();
v.add(h.get(key)); // 'κ°'μ 벑ν°μ μ½μ
}
return v; //λ¦¬ν΄ λ¬Έ
}
public static void main(String [] args) {
HashMap<String, String> h = new HashMap<String, String>(); // ν΄μ맡 h μμ±
h.put("λ²μ£", "112");
h.put("νμ¬", "119");
h.put("μ νλ²νΈ", "114");
Vector<String> v = hashToVector(h); // hashToVector() νΈμΆ
for(int n=0; n<v.size(); n++) // vμ λͺ¨λ μμμ λν΄ λ°λ³΅
System.out.print(v.get(n) + " ");
}
}