edit my code please

0 votes
asked Jan 8 by anonymous
package compressor;
import java.io.*;
import java.util.HashMap;
import java.util.Map;

public class Compressor.java
public static void main(String[] args)throws Exception
String output="";
Map<String, Integer> map = new HashMap<>();
File file = new File("C:\\Users\\owner\\Desktop\\Compressor\\src\\compressor\\sample.txt");   
BufferedReader br = new BufferedReader(new FileReader(file));   
String st;
String[] array;
int cnt=0;
while ((st = br.readLine()) != null) {
array=new String[st.length()];
array=st.split(" |\\."); /// split string as per [space] or [.] //here |\\ is used for regex OR
for(int i=0;i<array.length;i++){
String cntString=Integer.toString(cnt); /// convert int cnt to String cntString
if(cntString.length()+1 <array[i].length()){
map.putIfAbsent(array[i], cnt); //put key along with value in map
output+=array[i]+" ";
else{ /// key already present in map hence just withdraw value and add to output
output+="$"+map.get(array[i])+" ";
else /// for string like * , { ( } )
output+=array[i]+" ";

System.out.println("output = \n"+output);


Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.