mirror of
				https://github.com/ASDjonok/OOP_IO-2x_2023.git
				synced 2025-11-04 00:29:24 +02:00 
			
		
		
		
	Update lab3
This commit is contained in:
		
							parent
							
								
									1f0c160216
								
							
						
					
					
						commit
						f07b3b6617
					
				
							
								
								
									
										31
									
								
								lab3
									
									
									
									
									
								
							
							
						
						
									
										31
									
								
								lab3
									
									
									
									
									
								
							@ -1,6 +1,6 @@
 | 
			
		||||
import java.util.Scanner;
 | 
			
		||||
 | 
			
		||||
public class lab3 {
 | 
			
		||||
public class Lab5 {
 | 
			
		||||
    public static void main(String[] args) {
 | 
			
		||||
 | 
			
		||||
        int C17 = 2430 % 17;
 | 
			
		||||
@ -19,16 +19,40 @@ public class lab3 {
 | 
			
		||||
            String[] words = sb.toString().split("\\s+");
 | 
			
		||||
            for (int i = 0; i < words.length; i++) {
 | 
			
		||||
                String word = words[i];
 | 
			
		||||
                char lastLetter = word.charAt(word.length() - 1);
 | 
			
		||||
                char lastChar = word.charAt(word.length() - 1);
 | 
			
		||||
                if (!Character.isLetterOrDigit(lastChar)) {
 | 
			
		||||
                    // Last character is a punctuation mark
 | 
			
		||||
                    int lastLetterIndex = -1;
 | 
			
		||||
                    for (int j = word.length() - 2; j >= 0; j--) {
 | 
			
		||||
                        if (Character.isLetter(word.charAt(j))) {
 | 
			
		||||
                            lastLetterIndex = j;
 | 
			
		||||
                            break;
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                    if (lastLetterIndex != -1) {
 | 
			
		||||
                        char lastLetter = word.charAt(lastLetterIndex);
 | 
			
		||||
                        String newWord = "";
 | 
			
		||||
                        for (int j = 0; j < word.length() - 1; j++) {
 | 
			
		||||
                    if (word.charAt(j) != lastLetter) {
 | 
			
		||||
                            if (!Character.isLetterOrDigit(word.charAt(j)) || word.charAt(j) != lastLetter) {
 | 
			
		||||
                                newWord += word.charAt(j);
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                        newWord += lastChar;
 | 
			
		||||
                        words[i] = newWord;
 | 
			
		||||
                    }
 | 
			
		||||
                } else {
 | 
			
		||||
                    // Last character is a letter or a digit
 | 
			
		||||
                    char lastLetter = lastChar;
 | 
			
		||||
                    String newWord = "";
 | 
			
		||||
                    for (int j = 0; j < word.length() - 1; j++) {
 | 
			
		||||
                        if (!Character.isLetterOrDigit(word.charAt(j)) || word.charAt(j) != lastLetter) {
 | 
			
		||||
                            newWord += word.charAt(j);
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                    newWord += lastLetter;
 | 
			
		||||
                    words[i] = newWord;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            System.out.print("\nFinal string: ");
 | 
			
		||||
            System.out.println(String.join(" ", words));
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
@ -36,3 +60,4 @@ public class lab3 {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user