Advertisement
mrAnderson33

вторая лаба

Nov 22nd, 2017
589
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.51 KB | None | 0 0
  1. /*
  2. В каждом слове текста k-ю букву заменить заданным символом. Если k
  3. больше длины слова, корректировку не выполнять.
  4. */
  5. package com.company;
  6.  
  7. import java.util.InputMismatchException;
  8. import java.util.Scanner;
  9.  
  10. public class Main {
  11.  
  12.     public static void main(String[] args) {
  13.         char [] text = "In literary theory, a text is any object that can be read, whether this object is a work of literature, a street sign, an arrangement of buildings on a city block, or styles of clothing. It is a coherent set of signs that transmits some kind of informative message.[1] This set of symbols is considered in terms of the informative message's content, rather than in terms of its physical form or the medium in which it is represented.".toCharArray();
  14.  
  15.         Scanner in = new Scanner(System.in);
  16.  
  17.         System.out.printf("Please enter a number of character : ");
  18.  
  19.         int num =0;
  20.         String c;
  21.         try {
  22.             num = in.nextInt();
  23.         }
  24.         catch ( InputMismatchException ex)
  25.         {
  26.             System.err.println("Error , please enter a digit!");
  27.             System.exit(1);
  28.         }
  29.  
  30.         System.out.printf("Please enter a character : ");
  31.  
  32.         c = in.next();
  33.  
  34.         int k = 0;
  35.  
  36.         for(int i = 0; i < text.length; ++i)
  37.             if (text[i] ==' ') k = 0;
  38.             else  if (k++ == num - 1)  text[i] = c.charAt(0);
  39.  
  40.         System.out.println(text);
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement