Tuesday, September 12, 2017

Largest of Three Numbers in Java

In this article I would like to share with you a simple program that I wrote using Java to ask the user to give three numbers and then our program will determine which of the three numbers is the biggest or largest in terms of numerical value.  The code is very simple and easy to understand.

I am currently accepting programming work kindly contact me in the following email address for further details. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.





Sample Program Output


Program Listing


Largest_Three_Numbers.java


/**
 * 
 */
package largest_three;

import java.util.Scanner;

/**
 * @author Jake R. Pomperada
 * Bacolod City, Negros Occidental, Philippines
 * September 12, 2017   Tuesday
 */

public class Largest_Three_Numbers {

/**
* @param args
*/

public static void largest_three_values(int a, int b, int c)
{
if (a >= b && a >= c) {
System.out.print("\n\n");
System.out.print("The Largest Number is " + a + "." );
System.out.print("\n\n");
System.out.print("End of Program");
}
if (b >= a  && b >= c) {
System.out.print("\n\n");
System.out.print("The Largest Number is " + b + "." );
System.out.print("\n\n");
System.out.print("End of Program");
}
if (c >= a  && c >= a) {
   System.out.print("\n\n");
System.out.print("The Largest Number is " + c + "." );
System.out.print("\n\n");
System.out.print("End of Program");
}
}

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);

int val1=0;
int val2=0;
int val3=0;
System.out.print("\n\n");
System.out.print("===== Largest of Three Numbers in Java ====");
System.out.print("\n\n");
System.out.print("===== Written By: Mr. Jake R. Pomperada =====");;
System.out.print("\n\n");
System.out.print("Enter Three Numbers : ");
val1=input.nextInt();
val2=input.nextInt();
val3=input.nextInt();
largest_three_values(val1,val2,val3);
input.close();
}

}





No comments:

Post a Comment