Question: Where would I enter the input numbers in the code to get an output. Ex: number 1 would be 2 and number 2 would be
Where would I enter the input numbers in the code to get an output. Ex: number 1 would be 2 and number 2 would be 5 import java.util.Scanner; public class Percentages2 { public static void main(String[] args) { //Create a Scanner class object to read double values Scanner keyboard=new Scanner(System.in); double num1; double num2; double percent; System.out.println("Enter number 1"); //read num1 from the console num1=keyboard.nextDouble(); System.out.println("Enter number 2"); //read num2 from the console num2=keyboard.nextDouble(); //call the method computePercent with num1 and num2 percent =computePercent(num1, num2); System.out.println(num1+" is "+percent+"% of "+num2); //reverse the numbers //call the method computePercent with num2 and num1 percent =computePercent(num2, num1); System.out.println(num2+" is "+percent+"% of "+num1); } //Computes and retuns the num1 is percent of num2 public static double computePercent(double num1,double num2) { //num1 is percent of num2 is as follows return (num1/num2)*100; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
