Wednesday, 29 May 2013

Nested Prime

import java.io.*;
class Nestedprime
{
    public static void main(String args[])throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int i,m,n,d,c,j;
        System.out.println("Enter the number to check the prime numbers upto the range u wish");
        n=Integer.parseInt(br.readLine());
        for(i=1;i<=n;i++)
        {
            c=0;
            for(j=1;j<=i;j++)
            {
                if(i%j==0)
                {
                    c++;
                }
            }
       
            if(c==2)
            {
                System.out.println(i);
           }
        }  
    }
}

Nested Palindrome

import java.io.*;
class NestedPalindrome
{
    public static void main(String args[])throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int i,m,n,d,s;
        System.out.println("Enter the number to check the armstrong numbers upto the range u wish");
        n=Integer.parseInt(br.readLine());
        for(i=1;i<=n;i++)
        {
            m=i;
            s=0;
            while(m>0)
            {
                d=m%10;
                s=s*10+d;
                m=m/10;
            }
          if(s==i)
        {
            System.out.println(i);
        }
    }
    }
}
           
        

Nested Armstrong

import java.io.*;
class NestedArmstrong
{
    public static void main(String args[])throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int i,m,n,d,s;
        System.out.println("Enter the number to check the armstrong numbers upto the range u wish");
        n=Integer.parseInt(br.readLine());
        for(i=1;i<=n;i++)
        {
            m=i;
            s=0;
            while(m>0)
            {
                d=m%10;
                s=s+d*d*d;
                m=m/10;
            }
          if(s==i)
        {
            System.out.println(i);
        }
    }
    }
}