Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import static java.lang.System.*;
- import java.util.Random;
- import java.util.Scanner;
- import java.lang.Math;
- class Main{
- public static void main (String str[]) throws IOException {
- Scanner scan = new Scanner(System.in);
- System.out.println("Enter the first String:");
- String fst = scan.nextLine();
- System.out.println("Enter the replacement String:");
- String snd = scan.nextLine();
- int flag = 0;
- CharSequence s1 = "%";
- CharSequence s2 = snd.substring(0);
- for(int i = 0; i < fst.length(); i ++)
- {
- if (fst.charAt(i) == '%')
- {
- if (fst.matches("^.*[^a-zA-Z% ].*$") && flag == 0)
- {
- System.out.println("Error: Incorrect characters");
- flag += 99;
- }
- flag++;
- }
- }
- if (flag == 1)
- {
- System.out.print(fst.replace(s1 , s2));
- }
- else if (flag > 1 && flag < 98)
- {
- System.out.println("Error: Incorrect characters");
- }
- if (flag == 0)
- System.out.println("Error: no %");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement