Codemind Java Conditional Statements

BATHULA PRAVEEN (BP)
0

 

 ELECTRICITY BILL

import java.util.*;
class praveen{
    public static void main(String args[]){
        double cost,n;
        Scanner sc=new Scanner(System.in);
        String i=sc.nextLine();
        String name=sc.nextLine();
        n=sc.nextDouble();
        if(n<199)
        cost=1.20*n;
        else if(n<400)
        cost=1.5*n;
        else if(n<600)
        cost=1.8*n;
        else
        cost=2*n;
        if(cost>400)
            cost=(15/100.0)*cost+cost;
        else
        cost=cost+100;
        System.out.format("%.2f",cost);
    }
}

DISPLAY SEASON


import java.util.*;
class praveen{
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        int n,a;
        n=sc.nextInt();
        if(n==4 || n==5 ||n==6)
        System.out.println("Summer");
        else if(n==7 || n==8 ||n==9)
        System.out.println("Rainy");
        else if(n==11 || n==12 ||n==1)
        System.out.println("Winter");
        else if(n==2 || n==3)
        System.out.println("Spring");
        else
        System.out.println(-1);
    }
}

COLOR CODE

import java.util.*;
class praveen{
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        char n;
        n=sc.next().charAt(0);
        char a=Character.toUpperCase(n);
switch (a) {
  case 'V':
    System.out.println("Violet");
    break;
  case 'I':
    System.out.println("Indigo");
    break;
  case 'B':
    System.out.println("Blue");
    break;
  case 'G':
    System.out.println("Green");
    break;
  case 'Y':
    System.out.println("Yellow");
    break;
  case 'O':
    System.out.println("Orange");
    break;
  case 'R':
    System.out.println("Red");
    break;
    default:
    System.out.println(-1);
}
    }
}

CAR CHOICE 


import java.util.*;
class praveen{
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        int t,x1,x2,y1,y2;
        float c1,c2;
        t=sc.nextInt();
        for(int i=0;i<t;i++){
            x1=sc.nextInt();
            x2=sc.nextInt();
            y1=sc.nextInt();
            y2=sc.nextInt();
            c1=y1/(float)x1;
            c2=y2/(float)x2;
            if(c1<c2)
            System.out.println(-1);
            else if(c1>c2)
            System.out.println(1);
            else
            System.out.println(0);
        }
    }
}


import java.util.*;
class Solution
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        if(n==2)
        {
            System.out.println(1);
        }
        else if(n==1)
        {
            System.out.println(0);
        }
        else
        {
            System.out.println(2);
        }
    }
}

CAN SHARE EQUALLY?


import java.util.*;
class praveen{
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        int x,y;
        x=sc.nextInt();
        y=sc.nextInt();
        if(x==0 && y%2==0)
        System.out.print("YES");
        else if(x==0 && y%2!=0)
        System.out.print("NO");
        else if((x+2*y)%2==0)
        System.out.print("YES");
        else
        System.out.print("NO");
    }
}

PROGRAM TO CHECK VOWEL OR CONSONANT


import java.util.*;
class praveen{
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        char n;
        n=sc.next().charAt(0);
        if(n=='a' || n=='e'|| n=='i'|| n=='o'|| n=='u'|| n=='A'|| n=='E'|| n=='I'|| n=='O'|| n=='U')
        System.out.print("Vowel");
        else
        System.out.print("Consonant");
    }
}

CHECK IF NUMBER IS EVEN OR ODD


import java.util.*;
class praveen{
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        int n,a;
        n=sc.nextInt();
        if(n%2==0)
        System.out.print("Even");
        else
        System.out.print("Odd");
    }
}

PROGRAM TO CHECK WHETHER THE GIVEN INTEGER IS POSITIVE OR NEGATIVE


import java.util.*;
class praveen{
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        int n,a;
        n=sc.nextInt();
        if(n<0)
        System.out.print("Negative Number");
        else
        System.out.print("Positive Number");
    }
}


import java.util.*;
class swl
{
    static int is_prime(int n)
    {
        if(n==1)
        {
            return 0;
        }
        else
        {
            for(int i=2;i<=Math.sqrt(n);i++)
            {
                if(n%i==0)
                {
                    return 0;
                }
            }
            return 1;
        }
    }
    static int is_palindrome(int m)
    {
        int a = m;
        int s=0,b;
        while(m!=0)
        {
            b=m%10;
            s=s*10+b;
            m=m/10;
        }
        if(a==s)
        {
            return 1;
        }
        else
        {
            return 0;
        }
    }
    public static void main(String asd[])
    {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        scan.close();
        for(int i=n+1;i!=0;i++)
        {
            if(is_prime(i)==1)
            {
                if(is_palindrome(i)==1)
                {
                    System.out.print(i);
                    break;
                }
            }
        }
        
    }
}

GRADES OF RIDES


import java.util.*;
class praveen{
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        int a,b,c;
        boolean x,y,z;
        a=sc.nextInt();
        b=sc.nextInt();
        c=sc.nextInt();
        x=a>50;
        y=b>60;
        z=c>100;
        if(x && y && z)
        System.out.print(10);
        else if(x && y)
        System.out.print(9);
        else if(y && z)
        System.out.print(8);
        else if( x && z)
        System.out.print(7);
        else if(x || y || z)
        System.out.print(6);
        else
        System.out.print(5);
    }
}

RAIN DROP


import java.util.*;
class praveen{
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        int n;
        n=sc.nextInt();
        if(n%3==0)
        System.out.print("Pling");
        if(n%5==0)
        System.out.print("Plang");
        if(n%7==0)
        System.out.print("Plong");
        if(n%3!=0 && n%5!=0 && n%7!=0)
        System.out.print(n);
    }

Post a Comment

0Comments

Post a Comment (0)