NevLabs

Under Construction

Thursday, August 16, 2012

C++ program to perform array operations

//Program to create array,display array,search for an element and delete #include<iostream.h> #include<conio.h> #include<process.h> class array { int a[100]; int terms; public: array(); void create(); void display(); void search(); void delete(); }; array::array() {terms=0;} //create an array void array::create() { int i; cout<<"How many elements in the array:"; cin>>terms; if((terms>100)||(terms<0)) { cout<<"Sorry! the size does not support"; getch(); return; } {cout<<"enter the element"; for(i=0;i<terms;++i) cin>>a[i]; }} //Display...

Sunday, August 12, 2012

Java program to read and print student information

import java.io.*; class student { int slno; String name; student() { name=new String(); slno=0; } void get()throws IOException { BufferedReader br= new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter the name of the student: "); name=br.readLine(); System.out.print("\nEnter the Serial Number: "); slno=Integer.parseInt(br.readLine()); } void disp() { System.out.println("Serial Number : "+slno+"\nName : "+name); } } class studmark extends student { int m1,m2; studmark() { m1=m2=0; } void get()throws IOException { BufferedReader...

Java program to perform String sorting

import java.io.*; class stringsort { String s[]; int n; stringsort(int q) { s=new String[q]; n=q; } void sortstring()throws IOException { BufferedReader br= new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter The names: "); for(int i=0;i<s.length;i++){ System.out.print("name: "+(i+1)); s[i]=br.readLine();} } void sort() { for(int i=0;i<s.length-1;i++) for(int j=i+1;j<s.length;j++) { if(s[i].compareTo(s[j])>0) { String temp=s[i]; s[i]=s[j]; s[j]=temp; } } System.out.println("\nThe sorted array is: "); for(int...

Java program to read and print n student names

import java.io.*; class stringop1 { String s[]; int n; stringop1(int x) { s= new String[x]; n=x; } void get()throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); for(int i=0;i<n;i++) { System.out.print("\nName of student "+(i+1)+" : "); s[i]=br.readLine(); } } void disp() { System.out.print("\nThe Entered names are : "); for(int i=0;i<n;i++) System.out.print("\nName "+(i+1)+" : " +s[i]); } public static void main(String[] args)throws IOException { BufferedReader b=new BufferedReader(new InputStreamReader(System.in)); System.out.print("\nEnter...

Java program to find reverse of a number

import java.io.*; class reversenum { int num,dup,rev,rem; reversenum() { rev=rem=0; } void get()throws IOException { BufferedReader br= new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter the number : "); num=Integer.parseInt(br.readLine()); dup=num; while(dup>0) { rem=dup%10; rev=rev*10+rem; dup=dup/10; } } void disp() { System.out.println("\nThe reverse of " +num+" is "+rev); } public static void main(String[] args)throws IOException { reversenum r=new reversenum(); r.get(); r.disp(); ...

Java program to create user defined thread

class childthread implements Runnable { Thread t; childthread() { t=new Thread(this,"hello"); System.out.println("child created"); t.start(); } public void run() { try { for(int i=0;i<10;i++)  {  System.out.println("child "+i);  Thread.sleep(500);  } } catch(InterruptedException e) {} } } class parentthread { public static void main(String[] s) {  childthread c= new childthread(); try {  for(int i=0;i<10;i++)   {    System.out.println("main...

Java program to Implement Runnable class

class childthread implements Runnable { Thread t; childthread() { t=new Thread(this,"odd"); System.out.println("child created "+t); t.start(); } public void run() { try { for(int i=1;i<10;i++)  {  System.out.println("child "+i);  i++;  Thread.sleep(500);  } } catch(InterruptedException e) {} } } class oddeventhread { public static void main(String[] s) {  childthread c= new childthread(); try {  for(int i=2;i<=10;i++)   { ...

Java program to read and print n student information

import java.io.*; class nstudio { String s[]; int num; nstudio(int m) { s= new String[10]; num=m; } void getdata()throws IOException { BufferedReader br= new BufferedReader( new InputStreamReader(System.in)); System.out.println("Enter "+num+" Names : "); for(int i=0;i<num;i++) { System.out.print(i+1+ " : "); s[i]=br.readLine(); } } void dispdata() { System.out.println("\n The Entered Names are :"); for(int i=0;i<num;i++) { System.out.println(i+1+" : "+s[i]); } } public static void main(String[] args)throws IOException { nstudio n= new ...

Java Program to perform Matrix addition

class matrixaddition { int a[][]={{1,2,5},{1,0,2},{0,0,1}}; int b[][]={{2,2,4},{6,6,4},{3,7,8}}; int sum[][]; matrixaddition() { sum=new int[3][3]; } void display1() { for(int i=0;i<3;i++)   {    for(int j=0;j<3;j++)         System.out.print(a[i][j]+" ");      System.out.println("\t");   } } void display2() { for(int i=0;i<3;i++)   {    for(int j=0;j<3;j++)         System.out.print(b[i][j]+" ");      System.out.println("\t");  ...

Java program to perform matrix multiplication

public class matrixmultiplication { int a[][]={{1,2,3},{2,1,0},{0,1,2}}; int b[][]={{2,2,2},{1,0,1},{1,1,1}}; int prdt[][]; matrixmultiplication() { prdt=new int[3][3]; } void findproduct() { for(int i=0;i<3;i++) for(int j=0;j<3;j++) for(int k=0;k<3;k++) { prdt[i][j]+=a[i][k]*b[k][j]; } } void product() { for(int i=0;i<3;i++) { for(int j=0;j<3;j++) System.out.print(prdt[i][j]+" "); System.out.println("\n"); } } void display1() { for(int i=0;i<3;i++)   {    for(int j=0;j<3;j++)         System.out.print(a[i][j]+"...

Java program to find largest element of an programmer defined array

class largest { int a[]={12,10,8,9,44,23,44,66,84,1}; int large; void findlarge() { large=a[0]; for(int i=0;i<10;i++)     { if(large<a[i]) { large=a[i]; }    } System.out.println("Largest is "+large); } public static void main(String s[]) { largest l=new largest(); l.findlarge(); ...

Using of interface in java program

interface x { public void area(); } class y implements x { int a,b;            public void area() { a=5;b=7; System.out.println("Area is "+a*b);c } }  class z implements x { int a; public void area() { a=5; System.out.println("Area of box is "+a*a); } } class inter { public static void main(String[] args) { y a=new y(); z s=new z(); a.area(); s.area(); ...

Java Program to implement multilevel inheritance

import java.io.*; class xyz { int x,y; void get() throws IOException { BufferedReader br= new BufferedReader( new InputStreamReader (System.in)); System.out.print("Enter a num : "); x=Integer.parseInt(br.readLine()); System.out.print("Enter a num : "); y=Integer.parseInt(br.readLine()); } } class abc extends xyz { int a; void calc() { a=x+y; System.out.println("The sum of "+x+" & "+y+" is "+ a); } } class mno extends abc { int s; void disp() { s=x-y; System.out.println("Difference : "+ s); } } class inheritance { public static void main(String[]...

Java program to print Factorial of a number, as Programmers wish

class factorial { int f; factorial()            { f=1;            } void disp() { for(int i=1;i<5;i++)      { f=f*i; System.out.println(f);       } } public static void main(String s[])              { factorial f= new factorial(); f.disp();              ...

Program to do Exception Handling in java

import java.lang.Throwable; class exception { public static void main(String[] args) { int c; int a=5; int b=0; try { System.out.println("Hellow...."); c=a/b; System.out.println("Haiii"); } catch(Exception e) { System.out.println(e); } System.out.println("yippeeeee"); ...

Java program to Compare elements of an array

import java.io.*; class compelarray { int a[],big,small,n; compelarray(int x) { n=x; a=new int[n]; } void readarray()throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter elements of array: "); for(int i=0;i<n;i++) a[i]=Integer.parseInt(br.readLine()); } void compare() { big=small=a[0]; for(int i=0;i<n;i++) {if(big<a[i]) big=a[i]; if(small>a[i]) small=a[i]; } System.out.println("The biggest element is : "+big); System.out.println("The smallest...

Java program to find sum of the elements of an array

class arraysum        { int a[],sum; arraysum()     { a= new int[12]; sum=0; for(int i=0;i<12;i++)     { a[i]=i+1;     }   } void add()  { for(int i=0;i<12;i++)     { sum=sum+a[i];      } System.out.println("\t"+"sum of elements of array is "+sum);  } void disp() { for(int i=0;i<12;i++) { System.out.println(i+" "); } } public static void main(String s[])  { arraysum as = new arraysum(); as.disp(); ...