Showing posts with label JAVA. Show all posts
Showing posts with label JAVA. Show all posts
Tuesday, 2 April 2019
Saturday, 30 March 2019
Program to find area of rectangle using concept of Interface
interface Area
{
final static float pi = 3.14F;
float compute (float x, float y);
}
class Rectangle implements Area
{
public float compute (float x, float y)
{
return (x*y);
}}
class InterfaceTest
{
public static void main (String args[])
{
Rectangle rect = new Rectangle();
Area area;
area = rect;
System.out.println ("Area of rectangle ="+area.compute(10,20));
}
}
{
final static float pi = 3.14F;
float compute (float x, float y);
}
class Rectangle implements Area
{
public float compute (float x, float y)
{
return (x*y);
}}
class InterfaceTest
{
public static void main (String args[])
{
Rectangle rect = new Rectangle();
Area area;
area = rect;
System.out.println ("Area of rectangle ="+area.compute(10,20));
}
}
OUTPUT::
Thursday, 28 March 2019
Program to make Thread in Java using concept of multi threading
class A extends Thread
{
public void run ()
{
System.out.println("threadA started");
for (int i =1; i<=4; i++)
{
System.out.println("\tFrom Thread A: i="+i);
}
System.out.println("Exit from A");
}
}
class B extends Thread
{
public void run ()
{
System.out.println("threadB started");
for (int j =1; j<=4; j++)
{
System.out.println("\tFrom Thread B: j="+j);
}
System.out.println("Exit from B");
}
}
class C extends Thread
{
public void run ()
{
System.out.println("threadC started");
for (int k =1; k<=4; k++)
{
System.out.println("\tFrom Thread C: k="+k);
}
System.out.println("Exit from C");
}
}
class ThreadPriority
{
public static void main (String args[])
{
A threadA = new A();
B threadB = new B();
C threadC = new C();
threadC.setPriority(Thread.MAX_PRIORITY);
threadB.setPriority(threadA.getPriority()+1);
threadA.setPriority(Thread.MIN_PRIORITY);
System.out.println("started thread A");
threadA.start();
System.out.println("started thread B");
threadB.start();
System.out.println("started thread C");
threadC.start();
System.out.println("End of main thread");
}
}
{
public void run ()
{
System.out.println("threadA started");
for (int i =1; i<=4; i++)
{
System.out.println("\tFrom Thread A: i="+i);
}
System.out.println("Exit from A");
}
}
class B extends Thread
{
public void run ()
{
System.out.println("threadB started");
for (int j =1; j<=4; j++)
{
System.out.println("\tFrom Thread B: j="+j);
}
System.out.println("Exit from B");
}
}
class C extends Thread
{
public void run ()
{
System.out.println("threadC started");
for (int k =1; k<=4; k++)
{
System.out.println("\tFrom Thread C: k="+k);
}
System.out.println("Exit from C");
}
}
class ThreadPriority
{
public static void main (String args[])
{
A threadA = new A();
B threadB = new B();
C threadC = new C();
threadC.setPriority(Thread.MAX_PRIORITY);
threadB.setPriority(threadA.getPriority()+1);
threadA.setPriority(Thread.MIN_PRIORITY);
System.out.println("started thread A");
threadA.start();
System.out.println("started thread B");
threadB.start();
System.out.println("started thread C");
threadC.start();
System.out.println("End of main thread");
}
}
Friday, 22 March 2019
Wednesday, 20 March 2019
Program to print grade of student as given marks in 5 subject
import java.util.*;
class students
{
public static void main (String args [])
{
int m1,m2,m3,m4,m5,tm;
double per;
Scanner sc= new Scanner (System.in);
System.out.println ("Enter the marks of 5 subject");
m1= sc.nextInt ();
m2= sc.nextInt ();
m3= sc.nextInt ();
m4= sc.nextInt ();
m5= sc.nextInt ();
tm= m1+m2+m3+m4+m5;
per=(tm/500.0)*100;
if (per>=80)
{
System.out.println (per+"A");
}
else if (per>=70 && per<80)
{
System.out.println (per+"B");
}
else if (per>=60 && per<70)
{
System.out.println (per+"C");
}
else if (per>=60 && per<50)
{
System.out.println (per+"D");
}
else
{
System.out.println (per+"Fail");
}
}
}
class students
{
public static void main (String args [])
{
int m1,m2,m3,m4,m5,tm;
double per;
Scanner sc= new Scanner (System.in);
System.out.println ("Enter the marks of 5 subject");
m1= sc.nextInt ();
m2= sc.nextInt ();
m3= sc.nextInt ();
m4= sc.nextInt ();
m5= sc.nextInt ();
tm= m1+m2+m3+m4+m5;
per=(tm/500.0)*100;
if (per>=80)
{
System.out.println (per+"A");
}
else if (per>=70 && per<80)
{
System.out.println (per+"B");
}
else if (per>=60 && per<70)
{
System.out.println (per+"C");
}
else if (per>=60 && per<50)
{
System.out.println (per+"D");
}
else
{
System.out.println (per+"Fail");
}
}
}
Saturday, 9 March 2019
Program to subtract two number in Java
Here we learn how to write a program in java to subtract two numbers. We made two class here but you have to save your file name with the second class name because compiler starts execution on that class where main () is placed.
the program will be executed the same as the earlier addition program https://www.programmingponds.com/2019/02/program-to-add-two-number-in-java.html
class sub_num
{
public int sub (int a, int b)
{
return (a-b);
}
}
class subnum
{
public static void main (String args[])
{
int a,b;
a=40;
b=10;
sub_num subobj=new sub_num();
System.out.println("subtraction="+subobj.add(a,b));
}
}
{
public int sub (int a, int b)
{
return (a-b);
}
}
class subnum
{
public static void main (String args[])
{
int a,b;
a=40;
b=10;
sub_num subobj=new sub_num();
System.out.println("subtraction="+subobj.add(a,b));
}
}
Tuesday, 19 February 2019
Program to add two number in Java
Here we learn how to write a program in java to add two numbers. We made two class here but you have to save your file name with the second class name because compiler starts execution on that class where main () is placed.
class add_num
{
public int add (int a, int b)
{
return (a+b);
}
}
class Addnum
{
public static void main (String args[])
{
int a,b;
a=10;
b=23;
add_num addobj=new add_num();
System.out.println("Addition="+addobj.add(a,b));
}
}
Output::
class add_num
{
public int add (int a, int b)
{
return (a+b);
}
}
class Addnum
{
public static void main (String args[])
{
int a,b;
a=10;
b=23;
add_num addobj=new add_num();
System.out.println("Addition="+addobj.add(a,b));
}
}
Output::
Subscribe to:
Comments (Atom)
Featured post
Kalgudi Interview Round!!
Those who cleared the second round of kalgudi got an email from exceller to complete their Kalgudi Interview Round. So here we will discuss ...