conditionals
conditionals
conditionals
int a=5,b=15,c=4;
System.out.println(a);
else if(b>c)
System.out.println(b);
else
System.out.println(c);
}
package scconditions;
import java.util.Scanner;
int m1,m2,m3;
m1=sc.nextInt();
m2=sc.nextInt();
m3=sc.nextInt();
float avg=(float)(m1+m2+m3)/3;
if(avg>=70)
System.out.println("Grade A");
System.out.println("Grade B");
{
System.out.println("Grade C");
System.out.println("Grade D");
else
System.out.println("Grade E");
/*
int age;
age=sc.nextInt();
else
}*/
/*
Eben or Odd
int n;
n=sc.nextInt();
if(n%2==0)
else
} */
}
package scconditions2;
import java.util.*;
int year=scan.nextInt();
if(year%4==0)
if(year%100==0)
if(year%400==0)
else
else
{
System.out.println("Its a Leap Year");
else
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.*;
System.out.println("Enter a URL");
String url=scan.nextLine();
if(protocol.equals("http"))
else if(protocol.equals("ftp"))
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");
}
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
}*/
}
package practiceswitch;
String str="2";
switch(str)
break;
break;
break;
default : System.out.println("Invalid");
}
package scswitch1;
import java.util.*;
String domain=scan.nextLine();
String ext=domain.substring(domain.lastIndexOf(".")+1);
switch(ext)
break;
break;
break;
break;
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.*;
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();
String option=sc.nextLine();
option=option.toUpperCase();
switch(option)
break;
break;
case "MUL": System.out.println("Product is "+(x*y));
break;
break;
break;