fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. static void delete(int i) {
  11. System.out.println("delete " + i);
  12. }
  13.  
  14. static void add(int i, String s) {
  15. System.out.println("add " + i + " " + s);
  16. }
  17.  
  18. public static void main (String[] args) throws java.lang.Exception
  19. {
  20. String data = ""
  21. + "A,106,Chainsaw 12\"\r\n"
  22. + "D,102\r\n"
  23. + "d,104\r\n"
  24. + "a,107,Chainsaw 10\"";
  25.  
  26. Scanner fileChange = new Scanner(new StringReader(data));
  27. fileChange.useDelimiter(",|\r\n");
  28. while (fileChange.hasNext()) {
  29. String codeStr = fileChange.next();
  30. if ((codeStr.charAt(0) == 'D') || (codeStr.charAt(0) == 'd')) {
  31. delete(fileChange.nextInt());
  32. } else if ((codeStr.charAt(0) == 'A') || (codeStr.charAt(0) == 'a')) {
  33. add(fileChange.nextInt(), fileChange.next());
  34. } //else
  35. System.out.println("done " + codeStr);
  36. }
  37. }
  38. }
Success #stdin #stdout 0.06s 711680KB
stdin
Standard input is empty
stdout
add 106 Chainsaw 12"
done A
delete 102
done D
delete 104
done d
add 107 Chainsaw 10"
done a