Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
java,Runtime ??? help pleasewhat is wrong?? //code import java.io.*; import java.util.*; class Main{ static boolean validCodeC(char a[]) { int i; for(i=0;i<a.length;i++) if(Character.isUpperCase(a[i]))break; return (i==a.length); } static boolean validCodeJ(char a[]) { int i; for(i=0;i<a.length;i++) if(Character.isUpperCase(a[i]))break; return (i<a.length); } public static void main(String args[])throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); //BufferedReader br = new BufferedReader(new FileReader("in.txt")); StringBuffer s=new StringBuffer (); ArrayList<Character>array; StringTokenizer st; String linea; char codigo[]; int i,caso=1,tokens; //try{ while((linea=br.readLine())!=null) { s.append("sample output #"+(caso++)+"\n"); st=new StringTokenizer((linea=br.readLine().trim()),"_"); tokens=0; array=new ArrayList<Character>(); while(st.hasMoreTokens()) { st.nextToken(); tokens++; } codigo=linea.toCharArray(); if(tokens==1){ if(validCodeJ(codigo)) { for(i=0;i<codigo.length;i++) if(Character.isUpperCase(codigo[i])) s.append("_"+Character.toLowerCase(codigo[i])); else s.append(codigo[i]); } else s.append(linea); } else { if(validCodeC(codigo)) { for(i=0;i<codigo.length;i++) array.add(codigo[i]); for(i=0;i<array.size();i++) if(array.get(i)=='_'){ array.remove(i); array.set(i,Character.toUpperCase(array.get(i))); } for(i=0;i<array.size();i++) s.append(array.get(i)); }else s.append("Error!"); } br.readLine(); s.append("\n\n"); } System.out.println(s); //}catch(IOException e){} } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator