008-006-011

Method Return Values

Easy

Problem Description

Method Return Values

In this problem: You will define three methods with different return types (int getMax(int,int), String getGrade(int), boolean isPrime(int)) and use their return values in expressions.

Learning Objective: Understand the concept of method return values and how to use them effectively

Overview

Define the following three methods:

  • getMax(int a, int b): Returns the larger of two integers as int
  • getGrade(int score): Returns grade as String (90+: A, 80+: B, 70+: C, else: F)
  • isPrime(int n): Returns whether the number is prime as boolean

Specifications

  • Display result of getMax(10, 25)
  • Display result of getGrade(85)
  • Display results of isPrime(7) and isPrime(10)

Output Format

Max of 10 and 25: 25
Grade for 85: B
7 is prime: true
10 is prime: false

Ready to Try Running Code?

Log in to access the code editor and execute your solutions for this problem.

Don't have an account?

Sign Up