Saturday, 23 July 2016

Java Pro

Odd summation

/*Write your code here */
import java.util.Scanner;
class odd{
    
    public static void main(String args[]){
        Scanner r=new Scanner(System.in);
        int a,d,l,s=0;
        a=r.nextInt();
        d=r.nextInt();
        l=r.nextInt();
        if(a>=-1000 && d<=1000 && 1>=-1000000 && 1<=1000000){
            for(int i=a;i<=l;i=i+d){
                if((i%2)!=0)
                s=s+i;
            }
            System.out.println(s);
        }
    }
}

Sum


/*Write your code here */
import java.util.Scanner;
class odd{
    
    public static void main(String args[]){
        Scanner r=new Scanner(System.in);
        int a,d,l,s=0;
        a=r.nextInt();
        d=r.nextInt();
        l=r.nextInt();
        if(a>=-1000 && d<=1000 && 1>=-1000000 && 1<=1000000){
            for(int i=a;i<=l;i=i+d){
                if((i%2)!=0)
                s=s+i;
            }
            System.out.println(s);
        }
    }
}

Pakistan vs India Cricket match

/*Write your code here */
public class match{
    public static void main(String args[]){
        int total=282;
        float req=(float)(total-(3.2*10));
        float rate=req/40;
        System.out.println(rate);
    }
}

Special Eleven

/*Write your code here */
import java.util.Scanner;
class ohno{
    public static void main(String args[]){
        
        Scanner n=new Scanner(System.in);
        int a=n.nextInt();
        if(a>0)
        {
            if(a%11==0){
                System.out.println(a);
            }
            else
                System.out.println(a+" is not a special number");
        }
        else if(a<0)
            System.out.println("Invalid Input Specification");
    }
}

His master?s card

/*Write your code here */
import java.util.Scanner;
public class mno{
    public static void main(String args[]){
         Scanner q=new Scanner(System.in);
         int n=q.nextInt();
        if((n==34)||(n==37))
            System.out.println(n+" is issued by American Express");
        else if(n>=300 && n<=305)
            System.out.println(n+" is issued by Diners Club");
        else if(n>=3528 && n<=3589)   
            System.out.println(n+" is issued by JCB");
        else if(n>=51 && n<=55)   
            System.out.println(n+" is issued by Master");
        else if(n==4)   
            System.out.println(n+" is issued by Visa");
        else
            System.out.println(n+" is not a valid IIN");
    }
    
}

Squares and Sum

/*Write your code here */
import java.util.*;
class sum{
    public static void main(String args[]){
        Scanner n=new Scanner(System.in);
        int a=n.nextInt();
        int b=n.nextInt();
        a=Math.abs(a);
        b=Math.abs(b);
        if(a==0 || b==0){
            System.out.println("Invalid Input");
        }
        else if(a!=0 && b!=0){
             if(a%2==0 && b%2==0 || a%2!=0 && b%2!=0)
           {
                System.out.println(a*a+b*b);
           }
           else{
               System.out.println((a+b)*(a+b));
           }
        }
        
    }
}

Play with 6

/*Write your code here */
import java.util.Scanner;
class mno{
    public static void main(String args[]){
        
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        int c=a+b;
        int d=Math.abs(a-b);
        if(a==6 || b==6 || c==6 || d==6)
        
        System.out.println("You can play with "+a+" and "+b+".");
        else
         System.out.println("You can not play with "+a+" and "+b+".");
    }
}

No comments: