What's new

Help Java if else

SUNRAI

Established
Joined
Feb 1, 2018
Posts
506
Reaction
48
Age
22
Java:
/* Get three exam grades from the user and compute the average of the grades.
Output the average of the three exams. Together with the average,
also include a smiley face in the output if the average is greater than or equal to 60, otherwise output :-(. */

import java.util.Scanner;
public class average {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.print("Enter the first number: ");
        double num1 = scan.nextDouble();
        System.out.print("Enter the second number: ");
        double num2 = scan.nextDouble();
        System.out.print("Enter the third number: ");
        double num3 = scan.nextDouble();
        scan.close();
        System.out.print("The average of entered numbers is:" + avr(num1, num2, num3));
        if (avr = < 60) {
            System.out.println(":-)");
        } else {
            System.out.println(":-(");

        }
    }

    public static double avr(double a, double b, double c) {
        return (a + b + c) / 3;
    }

}
 

DestroyThem

Established
Baliktad condition mo, dapat <= mauna dapat yung < tapos sunod yung =, parang word lang yan pag iimplement. Pag Greater than or equals to (>=), Less than or equals to (<=)
 
Top