Ok so my question is , is there a way to loop something until a choice of Strings are inserted ?
case "John":
n = 12;
break;
case "Jenny":
n = 6;
break;
default:
System.out.print("Wrong Name");
Lets say in this i want to loop the user to input the name until he uses any of the above case values.Now i know that i can write a while loop and use the OR operator for each , But i have a lot of valid inputs so is there a simpler way to loop until correct switch name is entered by a user.? if its an incorrect one i want to display wrong name and prompt again for user to input
I am using Java.Any help regarding this is greatly appreciated. Thanks a lot in advance.
public static int[] amount(int n) {
int[] values = new int[6];
int i;
i=n+6+6;
values[a]=i;
return values;
}
public static void returnarray(){
int values[]=amount()
int i = 0;
if
(values[i]%==0)
{system.out.println("the value is an even value");
else{ System.out.print("Not so even");
}
}
the issue i am having is when i am tryin to return the value from the first array the amount() method requires the parameter , i am not sure to return the first array to the second due to it having a parameter (int n) , im not sure if i am making enough sense to you and the code is not exactly how i typed it .
Il make it clearer . I need to return the n value from the switch into one method where i will be using that n method to do a certain caluculation multiple times and store those values inside an array. and i will return this array into another method where i will do another calculation there and display the out put; what i am having the issue with is on how to return the array into the second method becz the first method has a parameter which is (int n) as described by @kaushal28