The task is as follows:
Count the number of words per line
Remove all "a" characters from a string
Remove every third character from the string
Code solves 2 conditions. This is the maximum I have reached, but the program curses.
How to implement the third item?
public static void main(String[] args) { /*1*/ Scanner in = new Scanner(System.in); String a = in.nextLine(); int c = a.split(" ").length; System.out.println("слов в строке : " + c); /*2*/ String b = a.replaceAll("a", ""); System.out.println("cтрока без a : " + b); /*3*/ int i = 3; int j; StringBuffer sb = new StringBuffer(a); int d = a.split("").length; System.out.println(d); d = d + 1; while (i <= d) { StringBuffer g = sb.deleteCharAt(i); System.out.println(g); i = i + 3; } }
StringIndexOutOfBoundsExceptionin theStringBuffer g=sb.deleteCharAt(i);stringStringBuffer g=sb.deleteCharAt(i);" was already useful and would show that you are serious about this. - Regent