Hallo brauche Hilfe mit diesem Programm, wo ich es brauche, um den Benutzer für 2 ganze Zahlen (Y und Z, wo ich meinen Fehler bekomme), wo man ein min und der andere sein wird ein Max und ich verstehe nicht, warum es nicht richtig läuft.Brauchen Sie Hilfe mit der Benutzereingabe von min und max
import java.util.Scanner;
public class sampleMethods {
public static void main(String[] args) {
printYikes();
int x = 12;
x = getAnInt("Please enter an integer min and a max seperated by a space: ",y, z);
System.out.println("\nThat was a valid Number.");
System.out.println("You entered " + x + "!");
System.out.println("x is " + x);
x = doubleMyNumber(x);
System.out.println("x is " + x);
x = tripleMyNumber(x);
System.out.println("x is " + x);
}
static void printYikes() {
System.out.println("Yikes");
}
static int doubleMyNumber(int a) {
int b = a * 2;
return b;
}
static int tripleMyNumber(int a) {
int c = a * 3;
boolean odd = isOddOrEven(c);
if (odd) {
System.out.println("Number is Odd!!");
} else {
System.out.println("Number is Even!!");
}
return c;
}
static boolean isOddOrEven (int d) {
boolean isOdd = false;
if (d % 2 == 0) {
isOdd = false;
} else {
isOdd = true;
}
return isOdd;
}
static int getAnInt(String prompt, int min, int max) {
Scanner keyboard = new Scanner(System.in);
boolean numberError = false;
int enteredNumber = 0;
String enteredString = "";
do {
try {
System.out.print(prompt);
enteredString = keyboard.nextLine(); //Read into a string
enteredNumber = Integer.parseInt(enteredString.trim()); //then cast as a integer
numberError = false; //if we haven't bailed out, then the number must be valid.
if (enteredNumber < min || enteredNumber > max) {
numberError = true;
System.out.println("Your entry: \"" + enteredNumber + "\" is out of range...Please try again");
}
} catch(Exception e) {
System.out.println("Your entry: \"" + enteredString + "\" is invalid...Please try again");
numberError = true; //Uh-Oh...We have a problem.
}
} while (numberError == true); //Keep asking the user until the correct number is entered.
return enteredNumber;
}
}