Advertisement
evgenko

Untitled

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