1. Hello World Application in Java
class helloworld
{
public static void main(String arg[])
{
System.out.println("Hello world!");
}
}
2.Adding two integers entered by the user in JAVA
import java.util.Scanner;
class addInteger{
public static void main( String [ ] args )
{
Scanner in =new Scanner ( System.in );
System.out.println("Enter first number:");
int a=in.nextInt();
System.out.println("Second number:");
int b=in.nextInt();
int c=a+b;
System.out.println("The sum is :" + c);
}
}
3.Generate the fibonacci series of n terms entered by the user in Java
import java.util.Scanner;
class bikal
{
public static void main(String args[])throws Exception
{
int i,n;
Scanner in=new Scanner(System.in);
long a[]=new long[20];
System.out.print("Enter number of Terms(less than 20):");
n=in.nextInt();
a[0]=1;a[1]=1;
System.out.print(" "+a[0]);
System.out.print(" "+a[1]);
for(i=2;i<=(n-1);i++)
{
a[i]=a[i-1]+a[i-2];
System.out.print(" "+a[i]);
}
}
}
4.Display the multiplication table of the number entered by the user in Java
import java.util.Scanner;
class addInteger{
public static void main( String [ ] args )
{
Scanner in =new Scanner ( System.in );
System.out.println("Enter first number:");
int a=in.nextInt();
System.out.println("Second number:");
int b=in.nextInt();
int c=a+b;
System.out.println("The sum is :" + c);
}
}
5.Solution of three simultaneous equations in Java
import java.util.Scanner;
public class bkl{
public static void main(String args [])throws Exception
{
matrix data=new matrix();
data.readdata();
data.del123();
data.showdata();
}
}
class matrix
{
int i,j,k,del,del1,del2,del3;
int a[][]=new int[3][4];
int c[][]=new int[3][4];
void readdata() throws Exception
{
Scanner in=new Scanner(System.in);
for(i=0;i<3;i++)
{
System.out.println("Enter the line(a"+(i+1)+"x+b"+
(i+1)+"y+c"+(i+1)+"z=d"+(i+1)+")");
for(j=0;j<4;j++)
{
c[i][j]=a[i][j]=in.nextInt();
}
}
del=a[0][0]*(a[1][1]*a[2][2]-a[1][2]*a[2][1])
-a[0][1]*(a[1][0]*a[2][2]-a[2][0]*a[1][2])
+a[0][2]*(a[1][0]*a[2][1]-a[2][0]*a[1][1]);
}
void del123()
{
for(i=0;i<3;i++)
a[i][0]=c[i][3];
del1=a[0][0]*(a[1][1]*a[2][2]-a[1][2]*a[2][1])
-a[0][1]*(a[1][0]*a[2][2]-a[2][0]*a[1][2])
+a[0][2]*(a[1][0]*a[2][1]-a[2][0]*a[1][1]);
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
{
a[i][j]=c[i][j];
}
}
for(i=0;i<3;i++)
a[i][1]=c[i][3];
del2=a[0][0]*(a[1][1]*a[2][2]-a[1][2]*a[2][1])
-a[0][1]*(a[1][0]*a[2][2]-a[2][0]*a[1][2])
+a[0][2]*(a[1][0]*a[2][1]-a[2][0]*a[1][1]);
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
{
a[i][j]=c[i][j];
}
}
for(i=0;i<3;i++)
a[i][2]=c[i][3];
del3=a[0][0]*(a[1][1]*a[2][2]-a[1][2]*a[2][1])
-a[0][1]*(a[1][0]*a[2][2]-a[2][0]*a[1][2])
+a[0][2]*(a[1][0]*a[2][1]-a[2][0]*a[1][1]);
}
void showdata()throws Exception
{
System.out.println("The solution is x,y,z="
+(del1/del)+","+(del2/del)+","+(del3/del));
}
}
0 comments:
Post a Comment