Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Roll no.- 32
Roll no.- 32
Experiment 01
Date: 10/01/2019
a. Sum
public class Exp1 {
c.Even odd
Roll no.- 32
int a=70;
if(a%2==0)
System.out.println("A is even");
else
System.out.println("A is odd");
}
}
d. Greatest no. in 3 numbers.
Roll no.- 32
for (i=2;i<=20;i+=2)
System.out.println(i);
for (i=5;i<=50;i+=5)
System.out.println(i);
}
}
Experiment 02
Date: 17/01/2019
Roll no.- 32
height=h;
}
}
public class Exp2_1 {
public static void main(String[] args) {
Dimensions box1=new Dimensions();
Dimensions box2;
box2=new Dimensions(8,7,6);
float volume;
volume=box1.vol(); //125
System.out.println("Volume of box1="+volume);
volume=box2.vol();
System.out.pri ntln("Volume of box2="+volume); //336
}
}
Result:
SAP ID -500063751
Roll no.- 32
Roll no.- 32
}
}
Result:
Experiment 03
Aim: Use inheritance and Overriding Concept
Roll no.- 32
}
figure1(int l ,int b){
len=l;
br=b;
}
}
class Box extends figure1{
int ht;
Box(){
len=6;
br=9;
ht=5;
}
public void show(){
System.out.println(" Inside Box class");
System.out.println(len);
System.out.println(br);
System.out.println(ht);
}
}
Roll no.- 32
r=fig;
r.show();
r=B1;
r.show();
}
}
class figure2{
int len;
int br;
public void show(){
System.out.println("Value of len and br" +len +br );
}
figure2(){
System.out.println("This is Superclass Constant");
len=-1;
br=-1;
}
figure2(int l ,int b){
len=l;
br=b;
}
}
class Box2 extends figure2{
int ht;
Box2(){
len=6;
br=9;
ht=510;
}
public void show(){
System.out.println(" Inside Box class");
System.out.println(len);
System.out.println(br);
System.out.println(ht);
super.show();
}
}
SAP ID -500063751
Roll no.- 32
Roll no.- 32
}
final class Box3 extends figure3{
int ht;
Box3(){
len=6;
br=9;
ht=510;
}
public final void show(){
System.out.println(" Inside Box class");
System.out.println(len);
System.out.println(br);
System.out.println(ht);
super.show();
}
}
Experiment 04
Aim: Code using throws, throw, try, catch and final. Create an Exception handling code
Code implementation:
SAP ID -500063751
Roll no.- 32
Dimension(int a)
{ detail = a;
class Rectangle
{ int L;
int B;
Int area;
Rectangle()
{ L = 2;
B = 3;
Rectangle(int l, int b)
{ L = l;
B = b;
if((L==0) || (B==0)){
Roll no.- 32
area = L * B;
Experiment 05
Aim: Use 5 string function.
Code implementation:
SAP ID -500063751
Roll no.- 32
//System.out.println(“Name”);
String s = “Chandigarh”;
s = s.concat(“ is good”);
String e = “Patiala”;
System.out.println(ans);
ans = f.contentEquals(g);
System.out.println(ans); //contentEquals
System.out.println(“String Length:”);
Output:
SAP ID -500063751
Roll no.- 32