Thursday, 30 August 2012

most important program is implemented by sitansu


MOST IMPORTANT PROGRAM Is PLIMENTED BY SITANSU
//ARMSTRONG IN JAVA
package com.swain.cell;

public class Armstrong {
public static void main(String args[])
  {
     int n, sum = 0, temp, r;
     n=407;
     temp = n;

     while( temp != 0 )
     {
        r = temp%10;
        sum = sum + r*r*r;
        temp = temp/10;
     }

     if ( n == sum )
        System.out.println(n+" is an armstrong number.");
     else
        System.out.println(n+" is not an armstrong number.");      
  }

}
//BINARY SEARCH IN JAVA
package com.swain.cell;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class BinarySearch {
public static void main(String args[])throws IOException{

int i;
InputStreamReader x=new InputStreamReader(System.in);
BufferedReader y=new BufferedReader(x);
int a[]=new int[10];
System.out.println("ENTER THE NUMBER TO BE SEARCHED");
int n=Integer.parseInt(y.readLine());
System.out.println("ENTER 10 NUMBERS FOR THE ARRAY");
for(i=0;i<10;i++)
{
a[i]=Integer.parseInt(y.readLine());
   } 
   System.out.println("CONTENTS OF ARRAY ARE");
   for(i=0;i<10;i++)
   {
    System.out.println(a[i]);
   }
   System.out.println("NUMBER TO BE SEARCHED IS "+n);
   int p=-1,mid,l=0,u=9;
   while(l<=u)
   {
    mid=(l+u)/2;
    if(a[mid]==n)
    {
    p=mid;
    break;
    }
    else if(n> a[mid])
    {
    l=mid+1;
    }
    else if(n<a[mid])
    {
    u=mid-1;
    }
   }
   if(p==-1)
   {
    System.out.println("NUMBER DOES NOT EXIST IN THE ARRAY");
   }
   else
   {
    System.out.println("NUMBER EXISTS AT THE INDEX "+p);
   }
}
}
//COUNT WORD IN JAVA
package com.swain.cell;

import java.util.StringTokenizer;

public class CountWords {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
        String st="how to count word in java?";
        int count=0;
        StringTokenizer stk=new StringTokenizer(st," ");
        while(stk.hasMoreTokens()){
            String token=stk.nextToken();
            count++;
        }
        System.out.println("Number of words are: "+count);

}

}
//MULTIPLECATION TWO STRING
package com.swain.cell;

public class Div {

public String Mul (int a, int b){
int sum=a*b;
System.out.println("Sum="+sum);
return "temp="+sum;
}
public static void main (String args[]){
Div p=new Div();
String str=null;
str=p.Mul(15, 5);
System.out.println(str);
}
}

No comments:

Post a Comment