Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.util.concurrent.ThreadLocalRandom;
- public class Switch {
- private static Scanner dd=new Scanner(System.in);
- public static void Switch1(String[] args) {
- int countX = 0,countGen = 0,i = 0;
- StringBuilder str=new StringBuilder();
- String st,str1,opt3;
- String check1 = "",check2="",check3="";
- int opt1 = 5,m = 0,rnd2,opt2;
- System.out.print("Inserisci simbolo pieno: ");
- opt3=dd.next();
- char c = opt3.charAt(0);
- System.out.print("Inserisci simbolo vuoto: ");
- opt3=dd.next();
- char p = opt3.charAt(0);
- while(true){
- System.out.print("Inserisci lunchezza riga: ");
- opt1=dd.nextInt();
- if(opt1>=3){break;}}
- while(m<opt1){
- rnd2 = ThreadLocalRandom.current().nextInt(0,2);
- if(rnd2==1){str.append(p);}
- else if (rnd2==0){str.append(c);}
- m++;
- }
- st=str.toString();
- System.out.println(st);
- while(countX!=st.length()
- ){
- while(true){
- check1=check2=check3="";
- countX=0;
- System.out.print("Inserisci dove cambiare: ");
- opt2=dd.nextInt()-1;
- if(opt2>=0&opt2<=opt1){break;}}
- try{
- if(st.charAt(opt2-1)==c){check1=Character.toString(p);}
- else if(opt2!=0&st.charAt(opt2-1)==p){check1=Character.toString(c);}
- }catch(java.lang.StringIndexOutOfBoundsException exc){}
- try{
- if(st.charAt(opt2)==c){check2=Character.toString(p);}
- else if(st.charAt(opt2)==p){check2=Character.toString(c);}
- }catch(java.lang.StringIndexOutOfBoundsException exc){}
- try{
- if(opt2!=opt1-1&st.charAt(opt2+1)==c){check3=Character.toString(p);}
- else if(opt2!=opt1-1&st.charAt(opt2+1)==p){check3=Character.toString(c);}
- }catch(java.lang.StringIndexOutOfBoundsException exc){}
- if(opt2==0&opt2==opt1-1){str1=st.substring(0, opt2)+check1+check2+check3+st.substring(opt2+2, st.length()-1);}
- else if(opt2==0){str1=check2+check3+st.substring(opt2+2, st.length());}
- else if(opt2==opt1-1){str1=st.substring(0, opt2-1)+check1+check2+check3;}
- else if(opt2>2){str1=st.substring(0, opt2-1)+check1+check2+check3+st.substring(opt2+2, st.length());}
- else{str1=st.substring(0, opt2-1)+check1+check2+check3+st.substring(opt2+2, st.length());}
- System.out.println(str1);
- st=null;
- st=str1;
- while(true){
- if(i==str1.length()){break;}
- if(str1.charAt(i)==c){countX++;}
- i++;
- }
- System.out.println(c+" = "+countX+" "+p+" = "+(str1.length()-countX));
- countGen++;
- i=0;
- }
- System.out.println("Hai vinto in "+countGen+" mosse!");
- dd.nextLine();dd.nextLine();
- }
- public static void main(String[] args) {
- while(true){for(int k=0;k<1000;k++){System.out.println();}Switch1(args);}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement