.

Friday, 27 March 2015

Program to find diagonal elements in matrix

import java.util.Scanner;
class diagonalm
{
 public static void main(String[] arg)
 {
  int i,j;
 int a[][]=new int[3][3];
 Scanner sc=new Scanner(System.in);
 for(i=0;i<3;i++)
 {
   for(j=0;j<3;j++)
 {
  a[i][j]=sc.nextInt();
 }
}
System.out.println("Left diagonal elements=0");
 for(int k=0;k<3;k++)
 {
   for(int l=0;l<3;l++)
 {
 if(k==l)
 {
 System.out.println(a[k][l]);
}
}
}
 System.out.println("Right diagonal elements=0");
 for(int m=0;m<3;m++)
 {
   for(int n=0;n<3;n++)
 {
  if(m+n==2)
 {
  System.out.println(a[m][n]);
 }
}
}
}
}


Read more ...

Download program of LOGIC GATE IN JAVA

AND GATE

package logicgate;
 public class and
{
 int z1;
 public int dooperation(int x1,int y1)
 {
  int z;
  z=x1*y1;
  z1=z;
 return(z1);
}
 

 }

 NOT GATE
package logicgate;

 public class not
 {

 public int dooperation(int x3)
 {
  int z3;
  {
   if(x3==0)
   z3=1;
   else
   z3=0;
   return(z3);
 }
 }
  }


OR GATE
package logicgate;

 public class or
{
 int z2;
 public int dooperation(int x2,int y2)
 {
 int z;
 z=x2+y2;
 z2=z;
  return(z2);
 }
 
 }

MAIN CLASS


import logicgate.and;
import logicgate.or;
import logicgate.not;

 class Main
{
 public static void main(String[] arg)
{
 and ob1=new and();
 or ob2=new or();
 not ob3=new not();
 ob1.dooperation(0,1);
 ob2.dooperation(0,0);
 ob3.dooperation(0);
}
}

Read more ...

Program to find pallindrome in JAVA

class Pallindrome
{
public static void main(String args[])
{
int num=131;
int r,temp,sum=0;
temp=num;
while(num!=0)
{
r=num%10;
num=num/10;
sum=sum*10+r;
}
if(sum==temp)
System.out.println("no. is pallindrome");
else
System.out.println("no. is not pallindrome");
}
}
Read more ...

Program to find electricity bill in JAVA using if and else conditions

class electricity
{
Public static Void main(String args[])
{
int unit=Integer.parseInt(args[1]);
String name=args[0];
float rupees=0.0f;
{
if (unit<100)
rupees=rupees +unit*.40;
else if(unit>100 && unit<300)
rupees=rupees+(unit-100)*.50;
else (unit>300)
rupees=rupees+(unit-300)*.60;
}
if(rupees<250)
{
System.out.println("name="+name);
System.out.println("unit="+unit+"rupees="+rupees);
}
else
{
rupees=rupees+(rupees*15)/100;
System.out.println("name="+name);
System.out.println("unit="+unit+"rupees="+rupees);
}}}

Read more ...

Program to find area of circle and cylinder in JAVA

class Area{

final float PI=3.14f;
float arac,aracy;
int r=2,h=3,l=4;
void areaofcircle()
{
arac=PI*r*r;
System.out.println("area of circle="+arac);
}
void areaofcylinder()
{
aracy=((PI*r*r*h)+(2*PI*r*l));
System.out.println("area of cylinder="+aracy);
}
}
class area2{

public static void main(String[] arg)
{
 area ob=new area();
 ob.areaofcircle();
 ob.areaofcylinder();
}
}

Read more ...

Swapping two variables with using third variable in JAVA

class swap
{
   public static void main(String []args)
   {
      int a=25;
      int b=10;
      System.out.println("Intially a="+a+"b="+b);
      a=a+b;
      b=a-b;
      a=a-b;
      System.out.println("a="+a+"\nb="+b);
   }
}
Read more ...

Program to find factorial in JAVA



class factorial{

public static void main(String args[])

{

int f=1,i;

for(i=1;i<=5;i++)

f=f*i;

System.out.println("factorial="+f);

}

}
Read more ...