Java Exp 1 Print
Java Exp 1 Print
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.
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.
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));
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);
}
}
OUTPUT :
CONCLUSISON:
Program To Implement Scientific Calculator Using Java was studied and implemented successfully