Question: JAVA Fix the errors in following code: import java.util.Scanner; public class Validation { public static String getString(Scanner in, String prompt, int maxLength) { boolean valid
JAVA Fix the errors in following code: import java.util.Scanner; public class Validation { public static String getString(Scanner in, String prompt, int maxLength) { boolean valid = true; String s = ""; System.out.print(prompt); System.out.print(" : "); do { s = in.nextLine(); if (s.length() > 0) { if (s.length() < maxLength) { valid = true; } else { System.out.printf("Minimum length is %d characters. Try again."); } } } while(!valid); return s; } public static int GetInteger(Scanner in, String prompt, int lower, int upper) { boolean valid = false, outOfRange = false; int input = -1; do { System.out.print(prompt); if (outOfRange) System.out.printf(" [between %d and %d inclusive]", lower, upper); System.out.print(": "); while (in.hasNextInt()) { in.nextDouble(); System.out.println("Please enter an integer."); } input = in.nextInt(); if (input >= 0 && input <= 100) { valid = true; } else { System.out.println("Value is out of range."); outOfRange = true; } } while (!valid); return input; } }
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
