Show syntactically correct Java code that requests at least one number from the
ID: 3621790 • Letter: S
Question
Show syntactically correct Java code that requests at least one number from the user. The program will store all the numbers the user provides into separate String variables, and it will use the appropriate methods from the wrapper classes to convert these Strings into numerical values. Afterwards, the program should use these numerical values to compute any mathematical formula that uses at least one method from the Math class and display the outcome with appropriate titles. Show a sample of an input/output interaction with your program.Explanation / Answer
import java.io.*; public class MathTest { public static void main(String[] args) throws IOException { System.out.print("Enter a positive number: "); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); double number = Double.parseDouble(in.readLine()); System.out.println(); System.out.println("The square root of "+number+" equals "+Math.sqrt(number)); } }
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.