programming session #3

This is my third try...
http://cdvideoweb.com/wp-content/uploads/2013/09/prog.png
photocourtesy:cdvideoweb



1.Armstrong Number.

/*
 *open source
/**
 *
 * @author lol ik
 */
import java.util.*;
public class Differentmethods {

   
    public static void main(String args[])
    {
        Scanner num = new Scanner(System.in);
        int b,sum=0,n,c;
        System.out.println("Enter d number to be checked");
        n=num.nextInt();
        b=n;
        while( b != 0)
        {
            c= b % 10;
            sum=sum+c*c*c;
            b=b/10;
        }
       
        if(n==sum)
        {
        System.out.print("Armstrong");
        }
        else
        {
            System.out.print("Not Armstrong");
        }
       
    }
   
}




2.Prime Number

/*
 opensource
 */
/**
 *
 * @author lol ik
 */
import java.util.*;
public class PrimeNumber {
    public static void main(String args[])
    {
        int n,i=0,c,flag=0;
        Scanner prime=new Scanner(System.in);
        System.out.print("Enter the number u wish to check ?");
        n=prime.nextInt();
       
        for(i=3;i<=n/2;)
        {
            if(n%i==0||n%2==0){
                 flag=1;
                 break;
            }
            i=i+2;
        }
        if(flag==1||n==4)
            System.out.print("Not prime");
        else
            System.out.print("prime");
    }
   
}

Comments

Popular Posts