0% found this document useful (0 votes)
3 views6 pages

Java Exp 1 Print

The document outlines an experiment to implement a scientific calculator using Java, detailing key concepts such as classes, objects, and loops. It includes a source code example that allows users to perform various mathematical operations. The conclusion states that the program was successfully studied and implemented.

Uploaded by

07.Ankita Pal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views6 pages

Java Exp 1 Print

The document outlines an experiment to implement a scientific calculator using Java, detailing key concepts such as classes, objects, and loops. It includes a source code example that allows users to perform various mathematical operations. The conclusion states that the program was successfully studied and implemented.

Uploaded by

07.Ankita Pal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Padre Conceição College Of Engineering

DATE: 22/01/2025 EXPERIMENT NO: 01


AIM: Program To Implement Scientific Calculator Using Java

THEORY:
Class: In Java, a class is a blueprint or template for creating objects (instances). It defines the properties
(fields) and behaviors (methods) that the objects created from the class will have.
Objects: An instance of a class. Objects represent real-world entities and contain properties (fields) and
behaviors (methods). For example, an object of the Scanner class is created to take input from the user.
The main function: The main( ) function is the entry point of a Java program. It's the method that is
executed first when you run a Java application. Every Java program must have a main( ) method to be
executed.

Do While Loop: The do while loop guarantees that the code block will execute at least once because the
condition is checked after the block is executed.

While Loop: The while loop checks the condition before executing the block of code, so if the condition is
false initially, the loop will not execute at all.

public static void main (String [],args)

It's is designated entry point for java applications.Its common components are defined as follows:

Public: the access modifier indicates that the main method is accessible from any other class.

Static: the keywords signifies that the main method belongs to the class itself,rather than an instance of
class.As a result,it can be invoked without creating an object of the class.

Void: this return type signifies that the main method does not return any value upon completion.

main-this is the identifier of the method.JVM looks for this method at the starting point of the program.

String []args: this parameter is an array of string objects which allows for command line arguments to be
passed into the program during execution.

Declaration of variable: you can declare a variable by specifying it's data type followed by variable
name.You can also assign a value at the time of declaration.

DEPARTMENT OF ELECTRONICS AND COMPUTER ENGINEERING, JAVA PROGRAMMING

PAGE NO. : 1 ROLL NO. : 23EC20


Padre Conceição College Of Engineering

Syntax: dataType variableName;

Or you can initialize it with a value:

datatype VariableName=value;

SOURCE CODE :
package calculatorr;
import java.util.*;
public class Calculatorr {
public static void main(String[] args) {
double a,b;
int ch;
Scanner obj = new Scanner (System.in);
System.out.println("Enter two numbers ");
a = obj.nextDouble();
b = obj.nextDouble();
do
{
System.out.println("1.Add, 2.Sub, 3.Mul, 4.Div, 5.Expo, 6.Sqrt(a), 7.Sqrt(b), 8.Exit");
System.out.println("Enter Operation of Choice");
ch = obj. nextInt();
switch (ch)
{
case 1 : System.out.println("Sum ="+(a+b));

DEPARTMENT OF ELECTRONICS AND COMPUTER ENGINEERING, JAVA PROGRAMMING

PAGE NO. : 2 ROLL NO. : 23EC20


Padre Conceição College Of Engineering

break;
case 2 : System.out.println("Difference ="+(a-b));
break;
case 3 : System.out.println("Product ="+(a*b));
break;
case 4 : System.out.println("Quotient ="+(a/b));
break;
case 5 : System.out.println("Power ="+(Math.pow(a,b)));
break;
case 6 : System.out.println("Sqrt(a)="+(Math.sqrt(a)));
break;
case 7 : System.out.println("Sqrt(b)="+(Math.sqrt(b)));
break;
default:
System.out.println("Exiting...");
break;
}
}
while (ch!=8);
}
}

DEPARTMENT OF ELECTRONICS AND COMPUTER ENGINEERING, JAVA PROGRAMMING

PAGE NO. : 3 ROLL NO. : 23EC20


Padre Conceição College Of Engineering

OUTPUT :

DEPARTMENT OF ELECTRONICS AND COMPUTER ENGINEERING, JAVA PROGRAMMING

PAGE NO. : 4 ROLL NO. : 23EC20


Padre Conceição College Of Engineering

DEPARTMENT OF ELECTRONICS AND COMPUTER ENGINEERING, JAVA PROGRAMMING

PAGE NO. : 5 ROLL NO. : 23EC20


Padre Conceição College Of Engineering

CONCLUSISON:
Program To Implement Scientific Calculator Using Java was studied and implemented successfully

DEPARTMENT OF ELECTRONICS AND COMPUTER ENGINEERING, JAVA PROGRAMMING

PAGE NO. : 6 ROLL NO. : 23EC20

You might also like