How to set max value inside an array

Viewed 18

I am trying to take only certain inputs in an array

int a=sc.nextInt();
int arr[]=new int[a];       
for(int i=0;i<a;i++){
    arr[i]=sc.nextInt();
    }

like here I want every member of the array arr(whos length is a) to be between 1 and 15. How do I do that??

1 Answers

ok, i solved it... first I need to store it in another variable like int x=sc.nextInt(); and then use&& operatoe to cheak it ..if(x>=1 && x<=15){}.

Related