Google+

Monday, December 30, 2013

Program to display CIRCULAR PRIME numbers..

This program is used to display the circular prime numbers within 100.

EXAMPLE:

 197,971,719..97,79..3..

PROGRAM :

package Blog;
/**
 * @author Raju
 */
public class cirprime {
   public static void main(String args[])
    {
        for(int number =1;number<100;number++){
             if(isCircularprime(number)){
              System.out.println(number);              
          }}
    }
    public static boolean isCircularprime(int number)
    {
        int i=1,count=0,length = (int)(Math.log10(number)+1);
        int temp = number;
        while(i<=length){
           if(isPrime(temp))
                    {
                      count++;  
                    }
           temp = rotate(number);
           i++;
        }
        if(count==length)
        {
            return true;
        }
        return false;
    }
    public static boolean isPrime(int number){
        for(int i=2; i<number; i++){
           if(number%i == 0){
               return false; //number is divisible so its not prime
           }
        }
        return true; //number is prime now
    }
    public static int rotate(int number)
    {
        int length = (int)(Math.log10(number)+1);       
        int rotate = number%10;
        rotate = rotate * (int) Math.pow(10, length-1);
        number = number/10;
        rotate = rotate + number;
        return rotate;
    }       

}


Saturday, December 28, 2013

Program for displaying EVEN / ODD , FIBONACCI numbers and to SWAP without using Temp.

 Java is used in a wide variety of computing platforms from embedded devices and mobile phones on the low end, to enterprise servers and supercomputers on the high end.

1) This program is used to display EVEN /ODD numbers within a range you specify.

EXAMPLE :

EVEN numbers : 0 2 4 6 8 10 12 14 16 18 20 ....
ODD numbers  : 1 3 5 7 9 11 13 15 17 19...

PROGRAM :

package Blog;
import java.util.Scanner;
/**
 * @author Arun
 */
public class evenodd {
    public static void main(String args[])
    {
        System.out.println("Enter the range till which EVEN and ODD number to be printed :");
        Scanner scn = new Scanner(System.in);
        int numb = scn.nextInt();
        System.out.println("EVEN numbers within range is :");
        for(int i=0;i<=numb;i+=2)
        {
            System.out.print(i+" ");
        }
        System.out.println();
        System.out.println("ODD numbers within range is :");
        for(int i=1;i<=numb;i+=2)
        {
            System.out.print(i+" ");
        }
    }    

}

2) This program is used to display FIBONACCI numbers within a range you specify.

EXAMPLE:

Fibonacci numbers : 0 1 1 2 3 5 8 13 ...

PROGRAM:

package Blog;
import java.util.Scanner;
/**
 * @author Arun
 */
public class fibonacci {
    public static void main(String [] args)
    {
        int i=0,temp,currval;
        Scanner scn = new Scanner(System.in);
        System.out.println("Enter the range till which fibonacci number to be displayed :");
        int fib = scn.nextInt();
        System.out.print(i+" ");
        temp=i;
        i++;
        currval=i;
        while(i<fib)
        {
         System.out.print(currval+" "); 
         currval = i + temp;
         temp = i;
         i = currval;                             
        }        
    }    
}

3) This program is used to SWAP two numbers WITHOUT use of TEMPORARY variable :

EXAMPLE :

Before Swapping : a = -10 , b = -20
After Swapping : a = -20,b=-10

PROGRAM :

package Blog;
import java.util.Scanner;
/**
 * @author Arun
 */
public class swap {
    public static void main(String args[])
    {
        Scanner scn = new Scanner(System.in);
        System.out.println("Enter number A :");
        int a = scn.nextInt();
        System.out.println("Enter number B :");
        int b= scn.nextInt();
        a=a+b;
        b=(a-b);
        a=(a-b);
        System.out.println("Value in A :"+a);
        System.out.println("Value in B :"+b);
    }
    
}

Friday, December 27, 2013

Program to Rotate a Number using JAVA

Java a platform independent programming language.In this program you can rotate the number using Java.

EXAMPLE :
Original number:54321
Rotated Number :15432

PROGRAM :
import java.util.Scanner;
/**
 * @author Arun
 */
public class rotatetest {
    public static void main(String args[])
    {
        Scanner scn = new Scanner(System.in);
        System.out.println("Enter the Number to rotate");
        int number = scn.nextInt();
        int length = (int)(Math.log10(number)+1);       
        int rotate = number%10;
        rotate = rotate * (int) Math.pow(10, length-1);
        number = number/10;
        rotate = rotate + number;
        System.out.println("Rotated numb is "+rotate);
    }
}

How to reverse only words in a string in place using java ??

In this program you can reverse the words in a string without changing the order of placement of words using JAVA.

Example : -
original string : emoclew  ot   dehsaelnu-ofni  !! 
Reversed output : welcome to info-unleashed !!

Program :

package test;
import java.util.Scanner;
/**
 * @author Arun
 */
public class strrev {
   String original , reverse="";
   int i=0,t=0;
   void test()
   {   
    Scanner in = new Scanner(System.in);
    System.out.println("Enter a string to reverse : ");
    original = in.nextLine();
    int length = original.length();
    for (;i <length ;i++ ){
     if(Character.isWhitespace(original.charAt(i))||i == length-1)
       {
        disp(i);
       }           
     }
     System.out.println();
   }
   void disp(int l)
    {       
      for(int j = i;j>=t;j--)
       {
         reverse = reverse+original.charAt(j);
       }
      System.out.print(reverse);
      t=i;
      reverse =" ";
    }
   public static void main(String args[])
    {
        strrev s = new strrev();
        s.test();
    }
}


Tuesday, December 24, 2013

How to reduce data usage while using computer browsers in limited data plan ??

Computer browsers are mainly designed for broadband connection.They load more content then the mobile browsers.As it loads a full fledged web page it uses more data to be transferred.when we browse through mobile connection via data card or tethering with limited data plan it will be difficult for limiting the data usage.

Here are few tips for reducing the data usage.

1. Enable Click-To-Play plugin
    when we load a web page flash contents too get loaded along with it.This Flash content can be fairly large in size. To prevent Flash content from loading, you can enable the click-to-play plugin feature in your browser. When you access a page containing content that needs plugins – usually Flash, but occasionally Silverlight or something else – you will see placeholder images\. Click the placeholder and the content will download and play.
With click-to-play plugins, plugins won’t run automatically. They will only download and use your bandwidth if you actually want to view them.

2. Disabling images
   Images in pages to eats up your data.But unlike flash contents they use less data when compared to flash.We can disable those images.
  • For Chrome: Open the Settings screen, click Show advanced settings at the bottom, and click the Content Settings button under Privacy. Select Do not show any images.
  • For Firefox: Open the Options window, click the Content icon, and uncheck Load images automatically.
3. Disable Automatic updates
   When automatic updates are on your browser/operating system starts to scan for updates and updates if any.This may consume large amount of data depending on the update size.

4. Request mobile Website 
   You may request for mobile websites.Mobile website make use of less data unlike normal website.

5. Use opera Turbo
    When Opera Turbo is enabled, webpages are compressed via Opera's servers so that they use much less data than the originals. This means that there is less to download, so you can see your webpages more quickly.
Enabling Opera Turbo is as simple as clicking the Opera Turbo icon at the bottom-left of the Opera browser window. When you are on a fast connection again and Opera Turbo is not needed, the Opera browser will automatically disable it.