Sunday, September 10, 2017

Sum of Four Numbers Using Methods in Java


In this article I would like to share with you guys a simple program to ask the user to give four numbers and then our program will compute it's sum using a method in Java. The code is very simple and easy to understand for people that are very new in Java programming I hope you will find my work useful. 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

/**
 * 
 */
package addition_four_numbers;

import java.util.Scanner;


/**
 * @author Jake Rodriguez Pomperada, MAED-IT
 * Location : Bacolod City, Negros Occidental Philippines.
 * Date     : September 10, 2017  Sunday  12:13 PM
 */
public class Addition_Four_Numbers {

public static int total_sum(int a,int b, int c, int d)
{
int find_sum=0;
find_sum = (a+b+c+d);
System.out.print("\n\n");
System.out.print("The total sum is  " + find_sum + ".");
return find_sum;
}
/**
* @param args
*/
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;
int val4=0;
System.out.print("\n\n");
System.out.print("===== Sum of Four Numbers Using Methods 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 First Number : ");
val1=input.nextInt();
System.out.print("Enter Second Number : ");
val2=input.nextInt();
System.out.print("Enter Third Number : ");
val3=input.nextInt();
System.out.print("Enter Fourth Number : ");
val4=input.nextInt();
total_sum(val1,val2,val3,val4);
input.close();

}

}



No comments:

Post a Comment