0% found this document useful (0 votes)
25 views

Format For Front Page

The document appears to be a Java program submitted by a student named Naveenkumar.K.K for their class EEE B at KPR Institute of Engineering and Technology. The program contains code for a basic calculator that allows a user to choose and perform an arithmetic operation (addition, subtraction, multiplication, or division) on two numbers input by the user. It uses conditional statements and exception handling to check for invalid inputs like division by zero.

Uploaded by

kmkesavan
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)
25 views

Format For Front Page

The document appears to be a Java program submitted by a student named Naveenkumar.K.K for their class EEE B at KPR Institute of Engineering and Technology. The program contains code for a basic calculator that allows a user to choose and perform an arithmetic operation (addition, subtraction, multiplication, or division) on two numbers input by the user. It uses conditional statements and exception handling to check for invalid inputs like division by zero.

Uploaded by

kmkesavan
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/ 7

KPR INSTITUTE OF ENGINEERING AND TECHNOLOGY

(Approved by AICTE, New Delhi, Affiliated to Anna University, Chennai-25, Accredited by NAAC with A Grade)

ARASUR, COIMBATORE- 641 407


DEPARTMRNT OF EEE

JAVA PROGRAMMING

SUBMITTED BY
NAME: NAVEENKUMAR.K.K
ROLL NO :14EE034
CLASS: EEE B

import java.util.Scanner;
class Calculator {
public static void main(String[] args){
Scanner s=new Scanner(System.in);
System.out.println(" Your choices : ");
System.out.println("1.Addtion");
System.out.println("2.Subtraction ");
System.out.println("3.Multiplication ");
System.out.println("4.Division");
System.out.println("Enter your CHOICE : ");
int i=s.nextInt();
System.out.println("Enter the First number");
int a=s.nextInt();
System.out.println("Enter the second number ");
int b=s.nextInt();
double result=0;
switch(i)
{
case 1:
result=a+b;
break;
case 2:
result=a-b;
break;
case 3:
result=a*b;
break;
case 4:
if(b==0)
{
System.out.println("Division not possible");
break;
}
else
result=a/b;
default:System.out.println("You have entered wrong choices");
}
System.out.println("RESULT = "+result);
}
}

Output:
Your choices : ");
System.out.println("1.Addtion");
System.out.println("2.Subtraction ");
System.out.println("3.Multiplication ");
System.out.println("4.Division");
System.out.println("Enter your CHOICE : ");
int i=s.nextInt();
System.out.println("Enter the First number");
int a=s.nextInt();
System.out.println("Enter the second number

import java.util.Scanner;
public class JavaProgram
{
public static void main(String args[])
{
int mark[] = new int[5];
int i;
float sum=0, avg;
Scanner scan = new Scanner(System.in);
System.out.print("Enter Marks Obtained in 5 Subjects : ");
for(i=0; i<5; i++)
{
mark[i] = scan.nextInt();
sum = sum + mark[i];
}
avg = sum/5;
System.out.print("Your Grade is ");
if(avg>80)
{
System.out.print("A");
}
else if(avg>60 && avg<=80)
{
System.out.print("B");
}
else if(avg>40 && avg<=60)
{
System.out.print("C");
}
else
{
System.out.print("D");
}
}
}

Output:
Enter the marks in 5 subject:60
70
80
90
100
Your grade is :B

package com.instanceofjava;
public class EncapsulationDemo {
String name;
int rno;
String address;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getRno() {
return rno;
}
public void setRno(int rno) {
this.rno = rno;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public void showInfo(){
System.out.println("Name: "+getName());

System.out.println("R.No: "+getRno());
System.out.println("Address: "+getAddress());
}
}

Output:
Name :Raju
R.NO:147
Address: Iris Watson
P.O. Box 283 8562 Fusce Rd.
Frederick Nebraska 20620
(372) 587-2335

You might also like