Words word Solitaire (small game in txt file)

In the D drive to open test.txt will be required to write the words which the words appear in the console Solitaire

package mypackage;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Scanner;

public class main {
    static String []w=new String[1000];
    static char [][]wa=new char[1000][2];
    static int i=0;
    
    static void ward() throws IOException 
    {
        HashMap<String, Integer>mp = new HashMap<>();
        mp.put("jack", 1);
        mp.put("Tom", 2);
        mp.put("rose", 3);
        mp.put("jack",4);
        try (BufferedReader in = new BufferedReader(new FileReader("D:\\test.txt"))
                ){
                String line;
                int c = 0;
                while(null != (line = in.readLine())) {
                    
                    String[] words = line.split("\\W");//Word boundary                 
                    for (String w: words) {
                         IF (w.trim () length () == 0.) The Continue ; 
                        w = w.toLowerCase (); // case-insensitive statistics                     
                        IF (! Mp.containsKey (W)) { 
                            mp.put (W, . 1 ); 
                        } the else {
                             int n-= mp.get (W); 
                            mp.put (W, n- + 1'd ); 
                        }                     
                    } 
                    
                } 
                for(String key : mp.keySet()) {
                    int v = mp.get(key);
//                    System.out.println(key+"\t"+v);          
                    w[i]=key;
                    i++;
                    }
                
            } catch (Exception e) {
                // TODO: handle exception
            }
    }    
    
    static void sw() 
    {
        for(int j=0;j<i;j++)
        {
            char[] chs = w[j].toCharArray();
            wa[j][0]=chs[0];
            for(Character ch:chs){
                wa[j][1]=ch;
            }        
//            System.out.print(wa[j][0]);
//            System.out.println(wa[j][1]);
        }
    }
    
    public static void jielong()
    {    
        System.out.println(w[0]);
        for(int x=1,y=0;x<=i;x++)
        {
            if(wa[y][1]==wa[x][0])
            {
                System.out.println(w[x]);
                y=x;
            }
        }
    }
    

    public static void main(String[] args) throws IOException {
        ward();
        sw();
        jielong();
        
        
        }
}

 

Guess you like

Origin www.cnblogs.com/sonofdemon/p/11723528.html