Advertisement
Dar954826

Switch[ENG].java

Feb 23rd, 2015
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.59 KB | None | 0 0
  1. import java.util.*;
  2. import java.util.concurrent.ThreadLocalRandom;
  3.  
  4. public class Switch {
  5.     private static Scanner dd=new Scanner(System.in);
  6.     public static void Switch1(String[] args) {
  7.         int countX = 0,countGen = 0,i = 0;
  8.         StringBuilder str=new StringBuilder();
  9.         String st,str1,opt3;
  10.         String check1 = "",check2="",check3="";
  11.         int opt1 = 5,m = 0,rnd2,opt2;
  12.         System.out.print("Insert full symbol: ");
  13.         opt3=dd.next();
  14.         char c = opt3.charAt(0);
  15.         System.out.print("Insert empty symbol: ");
  16.         opt3=dd.next();
  17.         char p = opt3.charAt(0);
  18.         while(true){
  19.         System.out.print("Insert length line: ");
  20.         opt1=dd.nextInt();
  21.         if(opt1>=3){break;}}
  22.         while(m<opt1){
  23.             rnd2 = ThreadLocalRandom.current().nextInt(0,2);
  24.             if(rnd2==1){str.append(p);}
  25.             else if (rnd2==0){str.append(c);}
  26.             m++;
  27.         }
  28.         st=str.toString();
  29.         System.out.println(st);
  30.         while(countX!=st.length()
  31.                 ){
  32.             while(true){
  33.                 check1=check2=check3="";
  34.                 countX=0;
  35.             System.out.print("Insert where change: ");
  36.             opt2=dd.nextInt()-1;
  37.             if(opt2>=0&opt2<=opt1){break;}}
  38.             try{
  39.             if(st.charAt(opt2-1)==c){check1=Character.toString(p);}
  40.             else if(opt2!=0&st.charAt(opt2-1)==p){check1=Character.toString(c);}
  41.             }catch(java.lang.StringIndexOutOfBoundsException exc){}
  42.             try{
  43.             if(st.charAt(opt2)==c){check2=Character.toString(p);}
  44.             else if(st.charAt(opt2)==p){check2=Character.toString(c);}
  45.             }catch(java.lang.StringIndexOutOfBoundsException exc){}
  46.             try{
  47.             if(opt2!=opt1-1&st.charAt(opt2+1)==c){check3=Character.toString(p);}
  48.             else if(opt2!=opt1-1&st.charAt(opt2+1)==p){check3=Character.toString(c);}
  49.             }catch(java.lang.StringIndexOutOfBoundsException exc){}
  50.             if(opt2==0&opt2==opt1-1){str1=st.substring(0, opt2)+check1+check2+check3+st.substring(opt2+2, st.length()-1);}
  51.             else if(opt2==0){str1=check2+check3+st.substring(opt2+2, st.length());}
  52.             else if(opt2==opt1-1){str1=st.substring(0, opt2-1)+check1+check2+check3;}
  53.             else if(opt2>2){str1=st.substring(0, opt2-1)+check1+check2+check3+st.substring(opt2+2, st.length());}
  54.             else{str1=st.substring(0, opt2-1)+check1+check2+check3+st.substring(opt2+2, st.length());}
  55.             System.out.println(str1);
  56.             st=null;
  57.             st=str1;
  58.             while(true){
  59.                 if(i==str1.length()){break;}
  60.                 if(str1.charAt(i)==c){countX++;}
  61.                 i++;
  62.             }
  63.             System.out.println(c+" = "+countX+"       "+p+" = "+(str1.length()-countX));
  64.         countGen++;
  65.         i=0;
  66.         }
  67.         System.out.println("You won in  "+countGen+" moves!");
  68.         dd.nextLine();dd.nextLine();
  69.     }
  70.  
  71.     public static void main(String[] args) {
  72.         while(true){for(int k=0;k<1000;k++){System.out.println();}Switch1(args);}
  73.     }
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement