java - Comparing an array to two static values -
java - Comparing an array to two static values -
so doing simple. made simple java programme come in guess roll stored in array , compared 2 numbers generated randomly. question how comparing of array against 2 number without referencing exact index (i.e. not array[0]=number[1])? doing figure out how array work. why else erroring?
public static void main (string [] args){      java.util.scanner input = new java.util.scanner(system.in);     int [] guess= new int [2];     system.out.print("enter " + guess.length + " values: ");     (int i=0; i<guess.length;i++)         guess[i] = input.nextint();      method(guess);    }  public static string method(int [] that){     int number1 = (int)(math.random() * 6);     int number2 = (int)(math.random() * 6);       (int =0;i<that.length;i++){         if(that[i]==number1 , that[i]+1==number2)         {              homecoming "you got it";         }         else         {               homecoming "try again";         }//end else     } //end }//end method       
you cannot write and , if want and 2 conditions write &&. in if  status think mean increment index that[i+1]==number2 , incrementing random number itself. if  status like:-
 if(that[i]==number1 && that[i+1]==number2)         {              homecoming "you got it";         }     else{       ..          }    also want  add together output you got it or try again not visible user, since calling method method(guess); main() returns string not returned string. have write  create ouput visible on console.
system.out.println(method(guess));        java 
 
Comments
Post a Comment