MapleStory Finger Point

🟀 JAVA/πŸ“šλͺ…ν’ˆ JAVA_ESSENTIAL

[λͺ…ν’ˆ JAVA ESSENTIAL] CH7 μ‹€μŠ΅λ¬Έμ œ

HYEJU01 2021. 11. 24. 22:48
"κ°œμ •νŒ: λͺ…ν’ˆ 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) + " ");
	}
}