hello
This commit is contained in:
parent
791294d17b
commit
f05eec5fea
56
dmd.java
Normal file
56
dmd.java
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
class area
|
||||||
|
{
|
||||||
|
void display()
|
||||||
|
{
|
||||||
|
System.out.println("Area");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class triangle extends area
|
||||||
|
{
|
||||||
|
Scanner sc = new Scanner(System.in);
|
||||||
|
int b,h;
|
||||||
|
void display()
|
||||||
|
{
|
||||||
|
System.out.println("Enter base & height:");
|
||||||
|
b = sc.nextInt();
|
||||||
|
h = sc.nextInt();
|
||||||
|
System.out.println("Area of triangle:"+(0.5*b*h));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class circle extends area
|
||||||
|
{
|
||||||
|
Scanner sc = new Scanner(System.in);
|
||||||
|
int r;
|
||||||
|
void display()
|
||||||
|
{
|
||||||
|
System.out.println("Enter radius:");
|
||||||
|
r = sc.nextInt();
|
||||||
|
System.out.println("Area of triangle:"+(3.14*r*r));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class dmd
|
||||||
|
{
|
||||||
|
public static void main(String[] args)
|
||||||
|
{
|
||||||
|
int ch;
|
||||||
|
area a = null;
|
||||||
|
Scanner sc = new Scanner(System.in);
|
||||||
|
System.out.println("1.Triangle\n2.Circle\nEnter Choice:");
|
||||||
|
ch = sc.nextInt();
|
||||||
|
switch(ch)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
a = new triangle();
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
a = new circle();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
a.display();
|
||||||
|
}
|
||||||
|
}
|
||||||
52
excep.java
Normal file
52
excep.java
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
class InvalidAgeException extends Exception
|
||||||
|
{
|
||||||
|
InvalidAgeException(String s)
|
||||||
|
{
|
||||||
|
super(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*class Testhrow
|
||||||
|
{
|
||||||
|
public static void validate (int age) throws InvalidAgeException
|
||||||
|
{
|
||||||
|
if(age < 18)
|
||||||
|
{
|
||||||
|
throw new InvalidAgeException("Not valid");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
System.out.println("Valid");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
class excep
|
||||||
|
{
|
||||||
|
public static void main(String args[])
|
||||||
|
{
|
||||||
|
Scanner sc = new Scanner(System.in);
|
||||||
|
int age = sc.nextInt();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if(age < 18)
|
||||||
|
{
|
||||||
|
throw new InvalidAgeException("Not valid");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
System.out.println("Valid");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Exception Occurs");
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
System.out.println("Rest of the code");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user