Zad3
Never
import java.lang.Math; import java.util.Arrays; import java.util.*; public class Main { public static void main(String[] args) { System.out.println("Hello World"); zad3(); } public static void zad3() { Scanner sc = new Scanner(System.in); int maxRepetLetter = 2; //Liczba powtórzeń litery przed zamianą na skróconą wersje char[] tmpLetter = new char[1]; //Sprawdzana nowa litera int tmpCount = 0; //Licznik powtórzonej litery int C =-1; do { System.out.println("Podaj liczbę zestawów [1;50]"); C = sc.nextInt(); }while(C<1 || C>50); C++; String[] longText = new String[C]; String[] shortText = new String[C]; for(int i=0; i<C; i++) { longText[i] = sc.nextLine(); } for(int i=0; i<C; i++) { shortText[i] = ""; } for(int i=1; i<C; i++) { for(int iText = 0; iText < longText[i].length(); iText++) { if(iText == 0) { tmpLetter[0] = longText[i].charAt(0); tmpCount++; } else if(tmpLetter[0] == longText[i].charAt(iText)) { tmpCount++; } else if(tmpLetter[0] != longText[i].charAt(iText)) { if(tmpCount<=maxRepetLetter) { for(int repetLetter = 0; repetLetter < tmpCount; repetLetter++) { shortText[i] += Character.toString(tmpLetter[0]); } } else { shortText[i] += Character.toString(tmpLetter[0]); shortText[i] += Character.toString((char)(tmpCount+'0')); } tmpCount=1; tmpLetter[0] = longText[i].charAt(iText); } } if(tmpCount<=maxRepetLetter) { for(int repetLetter = 0; repetLetter < tmpCount; repetLetter++) { shortText[i] += Character.toString(tmpLetter[0]); } } else { shortText[i] += Character.toString(tmpLetter[0]); shortText[i] += Character.toString((char)(tmpCount+'0')); } } for(int i=1; i<C; i++) { System.out.println(shortText[i]); } } }