Answer to Question #164815 in Algorithms for Kwame Hayford

Question #164815

Assignment 1


Write a program in Java that returns the maximum for three numbers


Assignment 2

Based on Assignment 1, write an algorithm for your implementation



1
Expert's answer
2021-02-18T14:37:33-0500

Assignment1

import java.util.Scanner;

public class Assignment1 {
   public static void main(String[] args) {
      // 'Keyboard reader'
      Scanner sc = new Scanner(System.in);
      // Variables for three numbers and max value
      int a, b, c, max;

      // Read numbers
      System.out.print("Please enter the first number: ");
      a = sc.nextInt();      
      System.out.print("Please enter the second number: ");
      b = sc.nextInt();      
      System.out.print("Please enter the third number: ");
      c = sc.nextInt();

      // Determine maximum of three numbers
      // If 'a' greater than 'b' and 'c', then 'a' is max
      if(a > b && a > c) max = a;
      // Otherwise if 'b' greater than 'a' and 'c', then 'b' is max
      else if(b > a && b > c) max = b;
      // Otherwise 'c' is the 'max' value
      else max = c;

      // Print result
      System.out.println("Max value=" + max);

      sc.close();      
   }
}

Assignment2

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS