Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner; //scanner import
- public class Percentages { //program begins
- public static void main(String[] args) { //main method begins
- Scanner input = new Scanner (System.in); //scanner declaration
- //variable declaration
- double num1, num2;
- //input statements to prompt the user to enter the values
- System.out.println("Please enter the first number: ");
- num1 = input.nextDouble();
- System.out.println("Please enter the second number: ");
- num2 = input.nextDouble();
- //method call
- computePercent(num1, num2);
- computePercent(num2, num1);
- } //main method ends
- //method computePercent takes on two double arguments and calculates and displays its percentage
- public static void computePercent (double no1, double no2) {
- double percent; //variable declaration
- //to calculate the percentage
- percent = (no1 / no2) * 100;
- //output statements for the percentage
- System.out.println(no1 + " is " +percent+ "%");
- System.out.println(" of " +no2);
- } //method computePercent ends
- } //program ends
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement