samedi 30 octobre 2021

how can i select a specify index from an array to use it in switch case

hi I'm beginner and i want to make a quiz math game how can i select a specify index of the random array and use it as case value.

                Random random=new Random();
                int num1= random.nextInt(30);
                int num2= random.nextInt(30);
    
                System.out.println(num1+"+"+num2+"=");
                int result=num1+num2;
    
                System.out.println("What is the answer of this operation?");
    
              int sugg1=random.nextInt(100);
              int sugg2=random.nextInt(100);
          
                int[] array = {sugg1,sugg2,result};
        
                Random rand = new Random();
        
                for (int i = 0; i < array.length; i++) {
                    int randomIndexToSwap = rand.nextInt(array.length);
    
                    int temp = array[randomIndexToSwap];
    
                    array[randomIndexToSwap] = array[i];
    
                    array[i] = temp;
                }
                System.out.println(Arrays.toString(array));

                switch (Arrays.toString(array)) {
//I NEED HELP HERE HOW CAN I SELECT A SPECIFY INDEX OF THE RANDOM ARRAY AND USE IT AS CASE VALUE
               case array:
                
               }



Aucun commentaire:

Enregistrer un commentaire