//Interface Example
interface InterfaceDemo
{
public void show();
public int display();
}
class A implements InterfaceDemo
{
public void message(int num)
{
System.out.println("Message method..."+num);
}
public void show()
{
System.out.println("show method...");
}
public int display()
{
System.out.println("display method...");
return(0);
}
}
class InrterfaceExample
{
public static void main(String jj[])
{
A a=new A();
a.message(5);
a.show();
a.display();
}
}
Output:-
About Me
- Amit Singh Thakur
- Raipur, Chhattisgarh, India
- Hi , I am Amit Thakur. I have worked as a QA Engineer for two years and as a Java Developer for one year in NIHILENT TECHNOLOGIES PVT. LTD., Pune.Currently I am working as DEAN (Research & Development) in Bhilai Institute of Technology, Raipur.
Monday, April 26, 2010
JAVA(Demo Of Final class, Method and variable)
//Demo of final class and Methods and Variables
final class A
{
final public void show()
{
final int num=100;
System.out.println("This is Show method of class A...");
num=50;
}
}
class B extends A
{
int num=200;
public void show()
{
System.out.println("This is Show method of class B...");
}
}
class FinalDemo
{
public static void main(String ll[])
{
B b=new B();
b.show();
}
}
Output:-
final class A
{
final public void show()
{
final int num=100;
System.out.println("This is Show method of class A...");
num=50;
}
}
class B extends A
{
int num=200;
public void show()
{
System.out.println("This is Show method of class B...");
}
}
class FinalDemo
{
public static void main(String ll[])
{
B b=new B();
b.show();
}
}
Output:-
JAVA(Count the No of Vowels in String)------
//Count the No of Vowels in String
import java.io.*;
class VowelsInString
{
public static void main(String dd[])throws Exception
{
String str;
int count=0;
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
System.out.println("Enter Your String..");
str=br.readLine();
int len=str.length();
for(int i=0;i
{
if(str.charAt(i)=='a' || str.charAt(i)=='e' || str.charAt(i)=='i' || str.charAt(i)=='o' || str.charAt(i)=='u')
{
count++;
}
}
System.out.println("Number of Vowels is "+count);
}
}
import java.io.*;
class VowelsInString
{
public static void main(String dd[])throws Exception
{
String str;
int count=0;
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
System.out.println("Enter Your String..");
str=br.readLine();
int len=str.length();
for(int i=0;i
{
if(str.charAt(i)=='a' || str.charAt(i)=='e' || str.charAt(i)=='i' || str.charAt(i)=='o' || str.charAt(i)=='u')
{
count++;
}
}
System.out.println("Number of Vowels is "+count);
}
}
JAVA(Reverse The String)------------------------------
//Reverse The String
class ReverseString
{
public static void main(String A[])
{
String str1="amit";
StringBuffer str2=new StringBuffer("");
int len=str1.length();
for(int i=len-1;i>=0;i--)
{
str2.append(str1.charAt(i));
}
System.out.println("Reverse of String is..."+str2);
}
}
// -----------------OR-----------------------------
//public class ReverseString
//{
// public static void main(String[] args)
// {
// String str = "What's going on?";
// System.out.println(ReverseStringTest.reverseIt(str));
// }
//}
//class ReverseStringTest
//{
// public static String reverseIt(String source)
// {
// int i, len = source.length();
// StringBuffer dest = new StringBuffer(len);
//
// for (i = (len - 1); i >= 0; i--)
// {
// dest.append(source.charAt(i));
// }
// return dest.toString();
// }
//}
class ReverseString
{
public static void main(String A[])
{
String str1="amit";
StringBuffer str2=new StringBuffer("");
int len=str1.length();
for(int i=len-1;i>=0;i--)
{
str2.append(str1.charAt(i));
}
System.out.println("Reverse of String is..."+str2);
}
}
// -----------------OR-----------------------------
//public class ReverseString
//{
// public static void main(String[] args)
// {
// String str = "What's going on?";
// System.out.println(ReverseStringTest.reverseIt(str));
// }
//}
//class ReverseStringTest
//{
// public static String reverseIt(String source)
// {
// int i, len = source.length();
// StringBuffer dest = new StringBuffer(len);
//
// for (i = (len - 1); i >= 0; i--)
// {
// dest.append(source.charAt(i));
// }
// return dest.toString();
// }
//}
JAVA(Sorting The Array)-------------------
//Sorting the Array
import java.io.*;
import java.util.*;
class DemoArray
{
public static void main(String aa[])throws Exception
{
int arr[]=new int[10];
DataInputStream dis=new DataInputStream(System.in);
System.out.println("Enter 10 elements in Array..");
for(int i=0;i<10;i++)
{
arr[i]=Integer.parseInt(dis.readLine());
}
System.out.println("Entered 10 elements in Array ....");
for(int i=0;i<10;i++)
{
System.out.print(" "+arr[i]);
}
Arrays.sort(arr);
System.out.println("");
System.out.println("Sorted 10 elements in Array ....");
for(int i=0;i<10;i++)
{
System.out.print(" "+arr[i]);
}
}
}
import java.io.*;
import java.util.*;
class DemoArray
{
public static void main(String aa[])throws Exception
{
int arr[]=new int[10];
DataInputStream dis=new DataInputStream(System.in);
System.out.println("Enter 10 elements in Array..");
for(int i=0;i<10;i++)
{
arr[i]=Integer.parseInt(dis.readLine());
}
System.out.println("Entered 10 elements in Array ....");
for(int i=0;i<10;i++)
{
System.out.print(" "+arr[i]);
}
Arrays.sort(arr);
System.out.println("");
System.out.println("Sorted 10 elements in Array ....");
for(int i=0;i<10;i++)
{
System.out.print(" "+arr[i]);
}
}
}
JAVA(Prime Number)---------------------
//Prime Number
import java.io.*;
class Prime
{
public static void main(String args[])
{
int num=0,flag=0;
System.out.println("Please Enter Your NUmber..");
try
{
DataInputStream dis=new DataInputStream(System.in);
num=Integer.parseInt(dis.readLine());
}
catch(Exception e){}
for(int i=2;i
{
if(num%i==0)
{
flag=1;
break;
}
else
{
flag=0;
}
}
if(flag==0)
{
System.out.println("Number is Prime NUmber..");
}
else
{
System.out.println("Number is Not Prime NUmber..");
}
}
}
import java.io.*;
class Prime
{
public static void main(String args[])
{
int num=0,flag=0;
System.out.println("Please Enter Your NUmber..");
try
{
DataInputStream dis=new DataInputStream(System.in);
num=Integer.parseInt(dis.readLine());
}
catch(Exception e){}
for(int i=2;i
{
if(num%i==0)
{
flag=1;
break;
}
else
{
flag=0;
}
}
if(flag==0)
{
System.out.println("Number is Prime NUmber..");
}
else
{
System.out.println("Number is Not Prime NUmber..");
}
}
}
JAVA(Fibbonacci Series)--------------------------
//Fibbonacci Series
//Fibbonacci Series
import java.io.*;
class Fibbo
{
public static void main(String arr[])
{
int num=0,a=0,b=1,c=0;
System.out.println("Enter The Number of Elements in Series..");
try
{
DataInputStream dis=new DataInputStream(System.in);
num=Integer.parseInt(dis.readLine());
}
catch(Exception e){}
System.out.println("Fibbonacci Series is:- ");
System.out.print(" "+a);
System.out.print(" "+b);
for(int i=0;i
{
c=a+b;
System.out.print(" "+c);
a=b;
b=c;
}
}
}
//Fibbonacci Series
import java.io.*;
class Fibbo
{
public static void main(String arr[])
{
int num=0,a=0,b=1,c=0;
System.out.println("Enter The Number of Elements in Series..");
try
{
DataInputStream dis=new DataInputStream(System.in);
num=Integer.parseInt(dis.readLine());
}
catch(Exception e){}
System.out.println("Fibbonacci Series is:- ");
System.out.print(" "+a);
System.out.print(" "+b);
for(int i=0;i
{
c=a+b;
System.out.print(" "+c);
a=b;
b=c;
}
}
}
Monday, April 19, 2010
JAVA(Number Palindrome or Not)--------------------------
// Palindrome Number or Not
import java.io.*;
class PalindromeNumber
{
public static void main(String []arr)
{
int num=0,ori=0,sum=0,dig=0;
System.out.println("Enter Any Number...");
try
{
DataInputStream dis=new DataInputStream(System.in);
num=Integer.parseInt(dis.readLine());
}
catch(Exception e){}
ori=num;
while(num!=0)
{
dig=num%10;
sum=sum*10+dig;
num=num/10;
}
if(sum==ori)
{
System.out.println("Number is Palindrome");
}
else
{
System.out.println("Number is Not Palindrome");
}
}
}
import java.io.*;
class PalindromeNumber
{
public static void main(String []arr)
{
int num=0,ori=0,sum=0,dig=0;
System.out.println("Enter Any Number...");
try
{
DataInputStream dis=new DataInputStream(System.in);
num=Integer.parseInt(dis.readLine());
}
catch(Exception e){}
ori=num;
while(num!=0)
{
dig=num%10;
sum=sum*10+dig;
num=num/10;
}
if(sum==ori)
{
System.out.println("Number is Palindrome");
}
else
{
System.out.println("Number is Not Palindrome");
}
}
}
JAVA(String Palindrome)--------------------------
// String Palindrome
import java.io.*;
class Palindrome
{
public static void main(String arr[])
{
String s1="",s2="";
int len=0,first=0,last=0,flag=0;
System.out.println("Enter The String..");
try
{
DataInputStream dis=new DataInputStream(System.in);
s1=dis.readLine();
}
catch(Exception e){}
len=s1.length();
System.out.println("Length is "+len);
first=0;
last=len-1;
while(first
{
if(s1.charAt(first)==s1.charAt(last))
{
flag=1;
}
else
{
flag=0;
}
first++;
last--;
}
if(flag==1)
{
System.out.println("Palindrome");
}
else
{
System.out.println("Not Palindrome");
}
}
}
import java.io.*;
class Palindrome
{
public static void main(String arr[])
{
String s1="",s2="";
int len=0,first=0,last=0,flag=0;
System.out.println("Enter The String..");
try
{
DataInputStream dis=new DataInputStream(System.in);
s1=dis.readLine();
}
catch(Exception e){}
len=s1.length();
System.out.println("Length is "+len);
first=0;
last=len-1;
while(first
{
if(s1.charAt(first)==s1.charAt(last))
{
flag=1;
}
else
{
flag=0;
}
first++;
last--;
}
if(flag==1)
{
System.out.println("Palindrome");
}
else
{
System.out.println("Not Palindrome");
}
}
}
JAVA(Multiplication of Two Matrix A anb B)--------------------------
//Multiplication of Two Matrix A anb B
import java.io.*;
class Matrix
{
public static void main(String dd[])
{
int A[][]=new int[3][3];
int B[][]=new int[3][3];
int C[][]=new int[3][3];
try
{
DataInputStream dis=new DataInputStream(System.in);
System.out.println("Enter Elements in Matrix A...");
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
A[i][j]=Integer.parseInt(dis.readLine());
}
}
System.out.println("Enter Elements in Matrix B...");
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
B[i][j]=Integer.parseInt(dis.readLine());
}
}
}
catch(Exception e){}
System.out.println("Multiplication of Matrix A and B is...");
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
C[i][j]=0;
for(int k=0;k<3;k++)
{
C[i][j]=A[i][k]*B[k][j]+C[i][j];
}
}
}
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
System.out.print(" "+C[i][j]);
}
System.out.println("");
}
}
}
import java.io.*;
class Matrix
{
public static void main(String dd[])
{
int A[][]=new int[3][3];
int B[][]=new int[3][3];
int C[][]=new int[3][3];
try
{
DataInputStream dis=new DataInputStream(System.in);
System.out.println("Enter Elements in Matrix A...");
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
A[i][j]=Integer.parseInt(dis.readLine());
}
}
System.out.println("Enter Elements in Matrix B...");
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
B[i][j]=Integer.parseInt(dis.readLine());
}
}
}
catch(Exception e){}
System.out.println("Multiplication of Matrix A and B is...");
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
C[i][j]=0;
for(int k=0;k<3;k++)
{
C[i][j]=A[i][k]*B[k][j]+C[i][j];
}
}
}
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
System.out.print(" "+C[i][j]);
}
System.out.println("");
}
}
}
Subscribe to:
Posts (Atom)