Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.54 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3. public class NumberFilter {
  4.     //public static void main(String[] args){
  5.     public void filter(String str){
  6.  
  7.  
  8.         PrintWriter outputStream =null;
  9.         try{
  10.         outputStream = new PrintWriter(new FileOutputStream(str));
  11.     }
  12.         catch(FileNotFoundException e){
  13.             System.out.println("Error creating the file");
  14.             System.exit(0);
  15.         }
  16.         String input;
  17.         int pairs =0;
  18.  
  19.         while(true){
  20.         Scanner scan = new Scanner(System.in);
  21.         System.out.println("Enter a String!");
  22.         input = scan.nextLine();
  23.        
  24.  
  25.         if (input.equalsIgnoreCase("quit")) break;
  26.  
  27.         //if (input.contains("aa") || input.contains("bb") || input.contains("cc") || input.contains("dd")){
  28.           //  System.out.println("Dont enter two or more consective numbers");
  29.             //input = scan.nextLine();
  30.         //}
  31.  
  32.         for (int i = 0; i < input.length()-1; i++) {
  33.             //alpha.length()-1 so you won't get an ArrayOutOfBoundsException
  34.             //in the if statement at the next line. i++ to stop the loop being
  35.             //infinite.
  36.             if (input.charAt(i) == input.charAt(i + 1)) {
  37.                 pairs++;
  38.                                 System.out.println("Dont enter two consective numbers or letters!");
  39.                                 input  = scan.nextLine();
  40.                         }
  41.                        
  42.                        
  43.         }
  44.            
  45.             outputStream.println(input);
  46.         }
  47.        
  48.             outputStream.close();
  49.  
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement