mrAnderson33

вторая лаба Java

Dec 21st, 2017
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.24 KB | None | 0 0
  1. /* input
  2. 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.
  3. kjfkljvdklfcvmdlkfmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm      sdlkkkkkkkkkkkkkkkk sdfsdf sdgfsdg sdgfg
  4. */
  5.  
  6. package com.company;
  7.  
  8. import java.io.*;
  9. import java.util.InputMismatchException;
  10. import java.util.Scanner;
  11.  
  12. public class Main {
  13.  
  14.     public static void main(String[] args)
  15.     {
  16.         Scanner in = new Scanner(System.in);
  17.  
  18.         System.out.printf("Please enter a number of character : ");
  19.  
  20.         int num =0;
  21.         String c;
  22.         try
  23.         {
  24.             num = in.nextInt();
  25.         }
  26.         catch ( InputMismatchException ex)
  27.         {
  28.             System.err.println("Error , please enter a digit!");
  29.             System.exit(1);
  30.         }
  31.  
  32.         if (num <= 0)
  33.         {
  34.             System.err.println("Error, index number must be a positive and  not equals zero ");
  35.             System.exit(2);
  36.         }
  37.  
  38.         System.out.printf("Please enter a character : ");
  39.  
  40.         c = in.next();
  41.  
  42.         if (c.length() > 1)
  43.         {
  44.             System.err.println("You should enter only one symbol");
  45.             System.exit(3);
  46.         }
  47.  
  48.         in.close();
  49.  
  50.         StringBuilder sb = new StringBuilder();
  51.  
  52.         try(FileInputStream fin = new FileInputStream("C:\\Users\\Василий\\IdeaProjects\\lab 02\\src\\com\\company\\input"))
  53.         {
  54.             BufferedReader bf = new BufferedReader(new InputStreamReader(fin));
  55.  
  56.             String str ;
  57.  
  58.             while ((str = bf.readLine()) != null)
  59.             {
  60.                 int k =0;
  61.                 for (char ch : str.toCharArray())
  62.                     sb.append((k = (ch == ' ' ? 0 : k + 1)) == num ? c : ch);
  63.             }
  64.  
  65.         }
  66.         catch (IOException ex)
  67.         {
  68.             System.err.println(ex.getMessage());
  69.             System.exit(1);
  70.         }
  71.  
  72.         System.out.println(sb);
  73.     }
  74.  }
Advertisement
Add Comment
Please, Sign In to add comment