Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- public class NumberFilter {
- //public static void main(String[] args){
- public void filter(String str){
- PrintWriter outputStream =null;
- try{
- outputStream = new PrintWriter(new FileOutputStream(str));
- }
- catch(FileNotFoundException e){
- System.out.println("Error creating the file");
- System.exit(0);
- }
- String input;
- int pairs =0;
- while(true){
- Scanner scan = new Scanner(System.in);
- System.out.println("Enter a String!");
- input = scan.nextLine();
- if (input.equalsIgnoreCase("quit")) break;
- //if (input.contains("aa") || input.contains("bb") || input.contains("cc") || input.contains("dd")){
- // System.out.println("Dont enter two or more consective numbers");
- //input = scan.nextLine();
- //}
- for (int i = 0; i < input.length()-1; i++) {
- //alpha.length()-1 so you won't get an ArrayOutOfBoundsException
- //in the if statement at the next line. i++ to stop the loop being
- //infinite.
- if (input.charAt(i) == input.charAt(i + 1)) {
- pairs++;
- System.out.println("Dont enter two consective numbers or letters!");
- input = scan.nextLine();
- }
- }
- outputStream.println(input);
- }
- outputStream.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement