|
|
back to boardShow all messages Hide all messagesI have a hard time submitting my first piece of code. Compilation error appeared and I have no idea why. The following is my code. import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; import java.util.Scanner; /** * Created by Tanya on 2016/9/5. */ public class ReverseRoot2 { Scanner in; PrintWriter out; public void work()throws Exception { List<Double> numlist = new ArrayList<Double>(); in = new Scanner(System.in); String line = ""; while(in.hasNextLine() && !(line = in.nextLine()).equals("")) { String[] strnums = line.split(" "); for(String strnum : strnums) { if(strnum.matches("[0-9]+\\.*[0-9]*")) { numlist.add(Double.parseDouble(strnum)); } } } out = new PrintWriter(System.out); int len = numlist.size(); for(int i = len - 1;i>=0;i--) { out.print(Math.sqrt(numlist.get(i).doubleValue()) + "\t"); } out.flush(); } static public void main(String[] args)throws Exception { ReverseRoot2 rr = new ReverseRoot2(); rr.work(); } } After you submit your code, if it gets "compilation error", within the next 15 minutes it is underlined — you can click on it and see the error message. |
|
|