Question
Please use this method, there might be a lot of missing part in it, but please complete containing those parts:
Import java.util.Scanner;
Scanner in=new Scanner(System.in);
system.out.println(“Enter a single positive int or positive double:”)
String input= in.nextLine();
Scanner lineOfInput=new Scanner (input);
If (lineOfInput.hasNextDouble()){
System.out.println(“theres a double in the input”);
}else{
System.out.println(“theres no double coming next in the input”);
}
Boolean inputIsValid=false;
//some kind of loop to run while (!inputIsValid){
//statements to validate input
inputIsValid=true;
while(userInput > 0) {
System.out.println(Math.sqrt(userInput));
userInput--;
}
}
Rooter.html Home Grades Modules Announcements Syllabus Download Rooter.html (1.68 KB) Write a complete Java program called "Rooter" (without the quotation marks) that Prompts the user to enter a singe posh ive integer or a single double value Checks whether the user did enter a single positive integer or double, and if the user didn't, prints an appropriate message and repeats the initial prompt until the user does enter a single positive integer or double. Uses a while loop (once the user enters valid data) and the Math.sqrt(0 to print on separate lines the square root of the number entered and the square roots of numbers that are smaller than the original number by a positive integral amount but greater than or equal to zero (but do not try to print out the square root of a negative number!) Uses the default ouput of Math.sqrt0 when printing the square roots. People For example: if the user enters 5.56, your program should output the following: 2.3579652245103193 2.1354156504062622 1.8867962264113207 1.5999999999999999 1.2489995996796794 0.748331477354788 But if the user enters 5.56 7 then you should repeat the prompt, because the entry is not a single positive integer or double value (There's a space between the 6 and the 7). Other examples of invalid input will be given in class Up to twenty-five points will be deducted if the graders or I find an example of input that your program doesn' handle correctly Questions on this assignment should be asked by the end of class on the Friday before the assignment is due
Explanation / Answer
Import java.util.Scanner;
Scanner in=new Scanner(System.in);
system.out.println(“Enter a single positive int or positive double:”)
String input= in.nextLine();
Scanner lineOfInput=new Scanner (input);
If (lineOfInput.hasNextDouble()){
System.out.println(“theres a double in the input”);
}else{
System.out.println(“theres no double coming next in the input”);
}
Boolean inputIsValid=false;
//some kind of loop to run while (!inputIsValid){
//statements to validate input
inputIsValid=true;
while(userInput > 0) {
System.out.println(Math.sqrt(userInput));
userInput--;
}
}