0% found this document useful (0 votes)
19 views16 pages

JAVA PROGRAMS

Uploaded by

hansbernabe12503
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views16 pages

JAVA PROGRAMS

Uploaded by

hansbernabe12503
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

NO

YEAR PROBLEM_BERNABE
NO
NO

YES

NO

YES

NO

YES
GRADE Problem_BERNABE
NO

YES

NO
YES

NO
YES

NO
YES

NO
YES

NO
YES
PARRKINGFEEProblem_BERNABE

ELECTRICBILLProblem_BERNABE

YES

YES

NO
NO
YES

YES

NO

NO
YES
YES
GRADEProblemUSING SWITCH_BERNABE
CommodityCodeProblemUsingSwitch_BERNABE

YES

NO
YES

YES
NO
YES

NO
YES
NO
YES

NO
NO YES
YES

NO
NO
YES YES
TRAPEZOIDPROBLEM_BERNABE

YES

NO

YES

NO YES

YES
JAVA PROGRAMS

import
java.util
.Scanne
r; public
class
if_case1
{
public static void main(String[]args){
Scanner enter = new
Scanner (System.in);
int x,y,z;
System.out.print("Enter x: ");
//prompt to enter a value of x x
= enter.nextInt();
System.out.print("Enter y: ");
//prompt to enter a value of y y
= enter.nextInt();
System.out.print("Enter z: ");
//prompt to enter a value of z z =
enter.nextInt();
if (x>y && y>z){ //1st
condition
System.out.print("The
highest number is: "+x
+"\n The median number is: "+y //1st output
+"\n The lowest numbes is: "+z
+"\n Ascending order "+z+" "+y+" "+x+ "\n ");
}

else if (y>x&&x>z){ //2nd


condition
System.out.print("The
highest number is: "+y
+"\n The median number is: "+x //2nd output
+"\n The lowest numbes is: "+z
+"\n Ascending order "+z+" "+x+" "+y+ "\n ");
}
else if (z>y&&y>x){ //3rd
condition
System.out.print("The
highest number is: "+z
+"\n The median number is: "+y//3rd output
+"\n The lowest number is: "+x
+"\nAscending order "+x+" "+y+" "+z+ "\n ");
}
else if (x>z&&z>y){ //4th
condition
System.out.print("The
highest number is: "+x
+"\n The median number is: "+z // 4th output
+"\n The lowest number is: "+y
+"\n Ascending order "+y+" "+z+" "+x+ "\n ");
}
else if (y>z&&z>x){ //5th
condition
System.out.print("The
highest number is: "+y
+"\n The median number is: "+z//5th output
+"\n The lowest number is: "+x
+"\n Ascending order "+x+" "+z+" "+y+ "\n ");
}

else if (z>x&&x>y){ //6th


condition
System.out.print("The
highest number is: "+z
+"\n The median number is: "+x // 6th output
+"\nThe lowest number is: "+y
+"\n Ascending order "+y+" "+x+" "+z+ "\n ");
}

}
import java.util.Scanner;
public class if_case2 {
public static void main(String[]args){
Scanner enter = new Scanner
(System.in);//prompt to enter year
System.out.print("Enter a year: ");
int year =
enter.nextInt();
if(year%100
==0){//1st
condition
System.out.print("It is a century year. ");//1st output
}
else if(year%4==0 ){//2nd
condition
System.out.print("It is a
leap year. ");//2nd output
}
else //last condition
System.out.print("It is a ordinary year. ");//last output
}

}
import
java.util
.Scanne
r; public
class
if_case3
{
public static void main(String[]args){
Scanner enter = new Scanner
(System.in); System.out.print("Enter
a Grade: ");//prompt to enter a
Grade int Grade = enter.nextInt();

if(Grade >=93 && Grade


<=99){// 1st condition
System.out.print("Excelent \
n");//1st output
}

else if(Grade >=87 && Grade


<=92){//2nd condition
System.out.print("Very Good
\n");//2nd output
}
else if(Grade >=80 && Grade
<=86){//3rd condition
System.out.print("Good \
n");//3rd output
}

else if(Grade >=70 && Grade


<=79){//4th condition
System.out.print("Fair \
n");//4th output
}
else if(Grade >=65 && Grade
<=69){//5th condition
System.out.print("Poor \
n");//5th output
}

Else// last condition


System.out.print("
Invalid \n");// last
output
}
}
import
java.util
.Scanne
r; public
class
if_case4
{
public static void
main(String[]args)
{ Scanner enter =
new Scanner
(System.in);
System.out.print("Enter number of hours:
");//prompt to enter parking hours int hours
= enter.nextInt();
if(hours <=4 && hours >0)
{//1st condition
System.out.print("Parking
Fee: PHP 35 ");//1st output
}
else if(hours <=0)
{ //2nd condition
System.out.print
("Invalid ");// 2nd
output
}

else if(hours >4 && hours <=15){//3rd


condition System.out.print("Parking Fee:
PHP "+((hours-4)*15+35));//3rd output
}
else condition//last condition
System.out.print("Parking Fee: PHP 250 ");//last output
}
}
import java
util,Scanner
public static void
main(String[]args)
{ Scanner enter =
new Scanner
(System.in);
System.out.print("Enter number of hours:
");//prompt to enter value of KWH int KWH =
enter.nextInt();
if(KWH <=400 && KWH>=0){//1st
condition System.out.printf("Electric bill
is P %.2f" ,(KWH*30.12));//1st output
}
else if(KWH<0)
{//2nd condition
System.out.print
("Invalid ");//2nd
output
}

else //last condition


System.out.printf("Electric bill is P %.2f" , (((KWH-
400)*25.23)+12048));//last output

You might also like