Advertisement
Dar954826

Switch[ITA].java

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