fork download
  1. class Ideone {
  2. public static void main(String[] args) {
  3. int counter = 0;
  4. String tgt = ":DD";
  5.  
  6. for (int i = 0; i < tgt.length(); i++) {
  7. if (tgt.length() <= 3 && tgt.charAt(0) == ':' || tgt.charAt(0) == ';') {
  8. if (tgt.length() == 2 && tgt.charAt(1) == ')' || tgt.charAt(1) == 'D') {
  9. counter += 1;
  10. }
  11. }
  12. }
  13. System.out.println(counter); // prints 3
  14.  
  15. counter = 0;
  16. for (int i = 0; i < tgt.length(); i++) {
  17. if (tgt.length() <= 3 && (tgt.charAt(0) == ':' || tgt.charAt(0) == ';')) {
  18. if (tgt.length() == 2 && (tgt.charAt(1) == ')' || tgt.charAt(1) == 'D')) {
  19. counter += 1;
  20. }
  21. }
  22. }
  23. System.out.println(counter); // prints 0
  24. }
  25. }
Success #stdin #stdout 0.06s 47000KB
stdin
Standard input is empty
stdout
3
0