conditionals

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 15

package relational;

public class Relational

public static void main(String[] args)

int a=5,b=15,c=4;

if(a>b && a>c)

System.out.println(a);

else if(b>c)

System.out.println(b);

else

System.out.println(c);

}
package scconditions;

import java.util.Scanner;

public class SCConditions

public static void main(String[] args)

int m1,m2,m3;

Scanner sc=new Scanner(System.in);

System.out.println("Enter marks of 3 Subjects ");

m1=sc.nextInt();

m2=sc.nextInt();

m3=sc.nextInt();

float avg=(float)(m1+m2+m3)/3;

if(avg>=70)

System.out.println("Grade A");

else if(avg>=60 && avg<70)

System.out.println("Grade B");

else if(avg>=50 && avg<60)

{
System.out.println("Grade C");

else if(avg>=40 && avg<50)

System.out.println("Grade D");

else

System.out.println("Grade E");

//Check if a person is young

/*

public static void main(String[] args)

int age;

Scanner sc=new Scanner(System.in);

System.out.println("Enter your Age ");

age=sc.nextInt();

if(age>=14 && age<=55)

System.out.println("You are Young");

else

System.out.println("you are Not Young");


}

}*/

/*

Eben or Odd

public static void main(String[] args)

int n;

Scanner sc=new Scanner(System.in);

System.out.println("Enter a number ");

n=sc.nextInt();

if(n%2==0)

System.out.println("It is a Even Number");

else

System.out.println("It is a Odd Number");

} */

}
package scconditions2;

import java.util.*;

public class SCConditions2

public static void main(String[] args)

Scanner scan=new Scanner(System.in);

System.out.println("Enter a Year number");

int year=scan.nextInt();

if(year%4==0)

if(year%100==0)

if(year%400==0)

System.out.println("Its a Leap Year");

else

System.out.println("Not a Leap Year");

else

{
System.out.println("Its a Leap Year");

else

System.out.println("Not a Leap Year");

/* Find Radix of a given number

public static void main(String[] args)

Scanner scan=new Scanner(System.in);

String num;

System.out.println("Enter a Number");

num=scan.nextLine();

if(num.matches("[01]+"))

System.out.println("Binary Radix=2");

else if(num.matches("[0-7]+"))
{

System.out.println("Octal Radix=8");

else if(num.matches("[0-9]+"))

System.out.println("Decimal Radix=10");

else if(num.matches("[0-9A-F]+"))

System.out.println("Hexa Radix=16");

else

System.out.println("Not a Number");

} */

}
package sccondition3;

import java.util.*;

public class SCCondition3

public static void main(String[] args)

Scanner scan=new Scanner(System.in);

System.out.println("Enter a URL");

String url=scan.nextLine();

String protocol=url.substring(0, url.indexOf(":"));

if(protocol.equals("http"))

System.out.println("Hypertext Transfer Protocol");

else if(protocol.equals("ftp"))

System.out.println("File Transfer Protocol");

String ext=url.substring(url.lastIndexOf(".")+1);

if(ext.equals("com"))

System.out.println("Commercial");

else if(ext.equals("org"))

System.out.println("Organisation");

else if(ext.equals("net"))

System.out.println("Network");
}

/* Display Day name, by taking Day number

public static void main(String[] args)

Scanner scan=new Scanner(System.in);

System.out.println("Enter a Day number");

int day=scan.nextInt();

if(day==1)

System.out.println("Mon");

else if(day==2)

System.out.println("Tue");

else if(day==3)

System.out.println("Wed");

else if(day==4)

System.out.println("Thur");

else if(day==5)
{

System.out.println("Fri");

else if(day==6)

System.out.println("Sat");

else if(day==7)

System.out.println("Sun");

else

System.out.println("Invalid Day Number");

}*/

}
package practiceswitch;

public class PracticeSwitch

public static void main(String[] args)

String str="2";

switch(str)

case "1": System.out.println("One");

break;

case "2": System.out.println("Two");

break;

case "3": System.out.println("Three");

break;

default : System.out.println("Invalid");

}
package scswitch1;

import java.util.*;

public class SCSwitch1

public static void main(String[] args)

Scanner scan=new Scanner(System.in);

System.out.println("Enter Domain name");

String domain=scan.nextLine();

String ext=domain.substring(domain.lastIndexOf(".")+1);

switch(ext)

case "com": System.out.println("Commercial");

break;

case "org": System.out.println("Organisation");

break;

case "gov": System.out.println("Government");

break;

case "net": System.out.println("Network");

break;

/* Display Day name


public static void main(String[] args)

Scanner scan=new Scanner(System.in);

System.out.println("Enter Day Number");

int day=scan.nextInt();

switch(day)

case 1: System.out.println("Mon");

break;

case 2: System.out.println("Tue");

break;

case 3: System.out.println("Wed");

break;

case 4: System.out.println("Thur");

break;

case 5: System.out.println("Fri");

break;

case 6: System.out.println("Sat");

break;

case 7: System.out.println("Sun");

break;

default: System.out.println("Invalid");

break;

}*/

}
package scswitch2;

import java.util.*;

public class SCSwitch2

public static void main(String[] args)

Scanner sc=new Scanner(System.in);

System.out.println("Menu");

System.out.println("====");

System.out.println("ADD");

System.out.println("SUB");

System.out.println("MUL");

System.out.println("DIV");

System.out.println("Enter 2 Numbers");

int x=sc.nextInt();

int y=sc.nextInt();

sc.nextLine();

System.out.println("Enter Option in Words ");

String option=sc.nextLine();

option=option.toUpperCase();

switch(option)

case "ADD": System.out.println("Sum is "+(x+y));

break;

case "SUB": System.out.println("Difference is "+(x-y));

break;
case "MUL": System.out.println("Product is "+(x*y));

break;

case "DIV": System.out.println("Ratio is "+(x/y));

break;

default: System.out.println("Invalid Option");

break;

You might also like