Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 15

PROGRAM 1

/
****************************************************************************
****************************
Name: Akanksha Sharma
Class: 2nd year, A1
E.no.: 220362
Program name : Write a program for addition of 2 numbers.
****************************************************************************
*****************************/

class Test
{
public static void main(String args[]){
int x,y,z;
x=10;
y=20;
z=x+y;
System.out.println("z = "+ z);}
}

OUTPUT:
PROGRAM 2
/
****************************************************************************
****************************
Name: Akanksha Sharma
Class: 2nd year, A1
E.no.: 220362
Program name : Write a program for division of 2 numbers.
****************************************************************************
*****************************/
class Div
{
public static void main(String args[]){
int x,y,z;
x=5;
y=20;
z=y/x;
System.out.println("z = "+ z);

}
}

OUTPUT:0
PROGRAM 3
/
****************************************************************************
****************************
Name: Akanksha Sharma
Class: 2nd year, A1
E.no.: 220362
Program name : Write a program for multiplication of 2 numbers.
****************************************************************************
*****************************/
class Mul
{
public static void main(String args[]){
int x,y,z;
x=5;
y=20;
z=x*y;
System.out.println("z = "+z);
}
}
OUTPUT:
PROGRAM 4
/
****************************************************************************
****************************
Name: Akanksha Sharma
Class: 2nd year, A1
E.no.: 220362
Program name : Write a program for subtraction of 2 numbers.
****************************************************************************
*****************************/
class Sub
{
public static void main(String args[]){
int x,y,z;
x=5;
y=20;
z=x-y;
System.out.println("z = "+z);
}
}

OUTPUT:
PROGRAM 5
/
****************************************************************************
****************************
Name: Akanksha Sharma
Class: 2nd year, A1
E.no.: 220362
Program name : Write a program to find area of a circle.
****************************************************************************
*****************************/
class Sub
{
public static void main(String args[]){
float a,pi,r;
pi=3.14;
r=5.00;
a=pi*r*r;
System.out.println("area = "+a);
}
}
OUTPUT:
PROGRAM 6
/
****************************************************************************
*************************
Name: Akanksha Sharma
Class: 2nd year, A1
E.no.: 220362
Program name : Write a program for the purpose of addition of two time where each time is
described by two variables h and m .
****************************************************************************
**************************/
class Timetest
{
int h;
int m;
void inpt(int a, int b)
{
h=a;
m=b;
}
void outpt()
{
System.out.println("h="+h+" m="+m );
}
void timeadd(Timetest t1, Timetest t2)
{
h=t1.h + t2.h;
m=t1.m + t2.m;
if(m>59)
{
m= m-60;
h= h+1;
}
}
}

class Tests
{
public static void main(String arg[])
{
Timetest o1 = new Timetest();
Timetest o2 = new Timetest();
Timetest o3 = new Timetest();
o1.inpt(17,18);
o2.inpt(10,58);
o3.timeadd(o1,o2);
o3.outpt();
}}
OUTPUT:
PROGRAM 7
/
****************************************************************************
****************************
Name: Akanksha Sharma
Class: 2nd year, A1
E.no.: 220362
Program name : Write a program to print the grades for entered marks, A,B,C,D,E,F on the
basis of marks range.

****************************************************************************
*****************************/

import java.util.Scanner;
class Grade{
public static void main(String[] args){
Scanner sc= new Scanner(System.in);
System.out.print("Enter marks to be graded: ");
int a= sc.nextInt();
if(a>=91 && a<=100){
System.out.print("Grade A");
}
else if(a>=82 && a<=90){
System.out.print("Grade B");
}
else if(a>=73 && a<=81){
System.out.print("Grade C");
}
else if(a>=60 && a<=72){
System.out.print("Grade D");
}
else if(a>=40 && a<=59){
System.out.print("Grade E");
}
else{
System.out.print("Grade F");
}
sc.close();
}
}

OUTPUT:
PROGRAM 8
/
****************************************************************************
*************************
Name: Akanksha Sharma
Class: 2nd year, A1
E.no.: 220362
Program name : Write a program for the purpose of addition of two time where each time is
described by three variables h, m and s .
****************************************************************************
**************************/

class Timetest {
int h;
int m;
int s;
void inpt(int a, int b, int c) {
h=a;
m=b;
s=c;
}
void outpt() {
System.out.println("h="+h+" m="+m+" s="+s );
}
void timeadd(Timetest t1, Timetest t2){
h=t1.h + t2.h;
m=t1.m + t2.m;
s=t1.s + t2.s;
if(m>59){
m= m-60;
h= h+1;
}
if(s>59){
s= s-60;
m= m+1; }
}
}
class Tests{
public static void main(String arg[])
{
Timetest o1 = new Timetest();
Timetest o2 = new Timetest();
Timetest o3 = new Timetest();
o1.inpt(17,18,60);
o2.inpt(10,58,10);
o3.timeadd(o1,o2);
o3.outpt(); }
}
OUTPUT:
PROGRAM 9
/
****************************************************************************
*************************
Name: Akanksha Sharma
Class: 2nd year, A1
E.no.: 220362
Program name : Write a program for the purpose of addition of two distances (m cm mm)
where each distance is described by three variables.
****************************************************************************
**************************/

class Distancetest{
int m;
int cm;
int mm;
void inpt(int a, int b, int c) {
m=a;
cm=b;
mm=c;
}
void outpt() {
System.out.println("m="+m+" cm="+cm+" mm="+mm );
}
void distadd( Distancetest d1, Distancetest d2){
m=d1.m +d2.m;
cm=d1.cm + d2.cm;
mm=d1.mm + d2.mm;
if (mm >= 10) {
cm += mm / 10;
mm %= 10;
}
if (cm >= 100) {
m += cm / 100;
cm %= 100;
}
}
}
class Tests{
public static void main(String arg[]){
Distancetest o1 = new Distancetest();
Distancetest o2 = new Distancetest();
Distancetest o3 = new Distancetest();
o1.inpt(100,70,60);
o2.inpt(150,50,10);
o3.distadd(o1,o2);
o3.outpt();
}}
OUTPUT:

PROGRAM 10
/
****************************************************************************
*************************
Name: Akanksha Sharma
Class: 2nd year, A1
E.no.: 220362
Program name : Write a program to find the sum of digits of a given number of length 3.
****************************************************************************
**************************/
class Testmain{
public static void main(String args[]) {

Test t1= new Test();


t1.sum(345);
}
}
class Test{

int a,b,c;

void sum(int num){


a=num%10;
num=num/10;
b=num%10;
c=num/10;
System.out.println("Sum of digits = "+(a+b+c));
}
}

OUTPUT:
PROGRAM 11
/
****************************************************************************
*************************
Name: Akanksha Sharma
Class: 2nd year, A1
E.no.: 220362
Program name : Write a program to find the reverse of a 3 digit number .
****************************************************************************
**************************/
class Testmain {
public static void main(String args[]) {

Test t1= new Test();


t1.result(345);

}
}
class Test{

int a,b,c;

void result(int num){


a=num%10;
num=num/10;
b=num%10;
c=num/10;
int result =(a*100)+(b*10)+(c*1);
System.out.println("reverse = "+result);

}
}

OUTPUT:
PROGRAM 12
/
****************************************************************************
*************************
Name: Akanksha Sharma
Class: 2nd year, A1
E.no.: 220362
Program name: Write a program using classes and objects just to double every element of a
1D array.
****************************************************************************
**************************/
import java.util.Scanner;
class Test{
int a[];
Test(){
a= new int[5];
}
void input(){
System.out.print("Enter the array elements :");
Scanner Sc= new Scanner(System.in);
for(int i=0;i<5;i++){
a[i]=Sc.nextInt();
}
}
void proc(){
for(int i=0;i<5;i++){
a[i]=2*a[i];
}
}
void output(){
for(int i=0;i<5;i++){
System.out.println(a[i]);
} System.out.println();
}
}
class Testmain{
public static void main(String[] args) {
Test t1= new Test();
t1.input();
t1.proc();
t1.output();
}
}
OUTPUT:
PROGRAM 13
/
****************************************************************************
*************************
Name: Akanksha Sharma
Class: 2nd year, A1
E.no.: 220362
Program name: Write a program using classes and objects just to double every element of a
2D array.
****************************************************************************
**************************/
import java.util.Scanner;
class Test{
int a[][];
Test(){
a= new int[3][3];
}
void input(){
System.out.print("Enter the array elements :");
Scanner Sc= new Scanner(System.in);
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
a[i][j]=Sc.nextInt();
}
}
}
void proc(){
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
a[i][j]=2*a[i][j];
}
}
}
void output(){
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
System.out.print(a[i][j]+" ");
} System.out.println();
}
}
}
class Testmain{
public static void main(String[] args) {
Test t1= new Test();
t1.input();
t1.proc();
t1.output();
}
}
OUTPUT:

You might also like