Practical 3: Write a program to enter two numbers and perform mathematical operations on them.

Program:

import java.util.Scanner;  
public class practical3
{
    public static void main(String args[])
    {
       int a, b, res;
       Scanner scan = new Scanner(System.in);    
       System.out.print("Enter Two Numbers : ");
       a = scan.nextInt();
       b = scan.nextInt();    
       res = a + b;
       System.out.println("Addition = " +res);    
       res = a - b;
       System.out.println("Subtraction = " +res);    
       res = a * b;
       System.out.println("Multiplication = " +res);    
       res = a / b;
       System.out.println("Division = " +res);
    }
  }

Output:



Comments

Popular posts from this blog

Practical 11 : Create a class called Student. Write a student manager program to manipulate the student information from files by using FileInputStream and FileOutputStream

Practical 9 : Write an interactive program to print a string entered in a pyramid form. For instance, the string “stream” has to be displayed as follows: