Good day.
There is a simple task: take a string and remove from it all the substrings of 3 characters. The substrings begin with 'y' and end with 'k', and from 'yakjkk', for example, you get 'jkk'.
The correct solution is:
public String stringCut(String str) { String result = ""; for (int i=0; i<str.length(); i++) { if (i+2<str.length() && str.charAt(i)=='y' && str.charAt(i+2)=='k') { i = i + 2; } else { result = result + str.charAt(i); } } return result; } My solution is very similar, it just comes from if not equal:
public String stringСut(String str) { String result = ""; for (int i=0; i<str.length(); i++) { if (i+2<str.length() && str.charAt(i)!='y' && str.charAt(i+2)!='k') { result = result + str.charAt(i); } else { i = i + 2; } } return result; } This code is compiled, however, only an empty string or an erroneous result is returned. With what it can be connected?
Thank you.
(a && b && c). You did(a && not(b) && not(c)), in response you tried to write(a && not(b) || not(c)), and according to de Morgan's rule everything should be inverted(not(a) || not(b) || not(c)). - tutankhamun