N. Achyut java,Java Introductions Write a program to input and add two numbers using static methods (procedural programming)

Write a program to input and add two numbers using static methods (procedural programming)

add two numbers using static methods

Write a program to input and add two numbers using static methods (procedural programming)

Procedural Programming :

  • In procedural programming, program is divided into small parts called functions.
  • Procedural programming follows top down approach.
  • There is no access specifier in procedural programming.
  • In procedural programming, function is more important than data.
  • Procedural programming is based on unreal world.

package assignments;
import java.util.*;
/**
 *
 * @author achyut1324
 */
public class AddtwoNumbers {
    
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.println("Enter two numbers to get sum:");
        int x = in.nextInt();
        int y = in.nextInt();
        
        System.out.println("The sum of "+ x +"and "+y +"is " + add(x,y));

    }
    
    public static int add(int x, int y){
        return x+y;
    }
}

Output Of the Program

run:
Enter two numbers to get sum:
5
6
The sum of 5and 6is 11
BUILD SUCCESSFUL (total time: 3 seconds)

Related Post