I'm attempting to practice classes methods since I'm very new to JAVA. In my full program I am using other global variables and they are working fine within my other methods. My question is how do i get the public String y to work inside the parameters of my isNum() method so that inside any method I can use isNum(y); The way it is now the String y is only within the scope of isNum but I want y to be global inside the paramters of isNum and within it. Simple answers as possible thank you so much.
public static String y;
public static boolean isNum(String y){
for(int i = 0; i < y.length(); i++){
if(!(y.charAt(i) >= 48 && y.charAt(i) <= 57)){
return false;
}
}
return true;
}
I want to use isNum in this loop and transfer the value of x into y. I know x is an int and y is a string. How would I make that work?
x = input.nextInt();
if(isNum(y){
while(x <=0 || x > 3){
System.out.println("Choose a correct gear number: ");
x = input.nextInt();
}
switch(x){
case 1:
System.out.println("You're in Gear 1");
break;
case 2:
System.out.println("Gear 2");
break;
case 3:
System.out.println("Gear3");
}
}
}