Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.io.*;
- import java.nio.charset.Charset;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.Map;
- import java.util.Scanner;
- public class Main
- {
- public static void aasd(String a){
- }
- public static void main(String[] args) {
- Scanner read = new Scanner(System.in);
- Map<String,String> cityCountry = new HashMap<String,String>();
- /*String workingDir = System.getProperty("user.dir");
- System.out.println("Current dir: "+workingDir);*/
- try (
- InputStream fileInput = new FileInputStream("empty.txt");
- InputStreamReader inputStreamRead = new InputStreamReader(fileInput, Charset.forName("UTF-8"));
- BufferedReader bufferRead = new BufferedReader(inputStreamRead);
- ) {
- String line;
- while ((line = bufferRead.readLine()) != null) {
- if (line.contains(",")) {
- String[] strings = line.split(",");
- cityCountry.put(strings[0], strings[1]);
- }
- }
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- boolean unStop = true;
- while (unStop){
- System.out.print("Write the name of the city or write 'STOP' for end: ");
- String city =read.next();
- if ((city).equals("STOP"))
- unStop=false;
- if(unStop){
- String country = cityCountry.get(city);
- if (country!=null)
- System.out.println("Country: "+country);
- else System.out.println("Country doesn't exist");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement