Advertisement
evgenko

Untitled

Sep 6th, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.81 KB | None | 0 0
  1. package com.company;
  2.  
  3.  
  4. import java.io.*;
  5. import java.nio.charset.Charset;
  6. import java.util.ArrayList;
  7. import java.util.HashMap;
  8. import java.util.Map;
  9. import java.util.Scanner;
  10.  
  11. public class Main {
  12.     public static void aasd(String a) {
  13.  
  14.  
  15.     }
  16.  
  17.     public static void main(String[] args) {
  18.         Scanner read = new Scanner(System.in);
  19.         Map<String, String> cityCountry = new HashMap<String, String>();
  20.  
  21.  
  22.         /*String workingDir = System.getProperty("user.dir");
  23.         System.out.println("Current dir: "+workingDir);*/
  24.         try (
  25.                 InputStream fileInput = new FileInputStream("empty.txt");
  26.                 InputStreamReader inputStreamRead = new InputStreamReader(fileInput, Charset.forName("UTF-8"));
  27.                 BufferedReader bufferRead = new BufferedReader(inputStreamRead);
  28.         ) {
  29.             String line;
  30.             while ((line = bufferRead.readLine()) != null) {
  31.  
  32.                 if (line.contains(",")) {
  33.                     String[] strings = line.split(",");
  34.                     cityCountry.put(strings[0], strings[1]);
  35.                 }
  36.             }
  37.         } catch (FileNotFoundException e) {
  38.             e.printStackTrace();
  39.         } catch (IOException e) {
  40.             e.printStackTrace();
  41.         }
  42.  
  43.  
  44.         boolean unStop = true;
  45.         while (unStop) {
  46.             System.out.print("Write the name of the city or write 'STOP' for end: ");
  47.             String city = read.next();
  48.             if ((city).equals("STOP"))
  49.                 unStop = false;
  50.             if (unStop) {
  51.                 String country = cityCountry.get(city);
  52.                 if (country != null)
  53.                     System.out.println("Country: " + country);
  54.                 else System.out.println("Country doesn't exist");
  55.             }
  56.         }
  57.  
  58.  
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement