Java Basic Activities: If else and nested else if statements



==========================
Code: 
===========================
public class Test27_Pereda_ifelse {

public static void main(String [] args) {

int m=100, n=100;

if (m==n )  {

System.out.println("m is equal to n");

}

else {
System.out.println("m is not equal to n");


}
}

}

================================


===========================
Code: 
==============================
import java.util.Scanner;

public class Test28_Pereda_ifelse2 {

public static void main(String [] args) {

int pvail;
Scanner input = new Scanner(System.in);

System.out.println("Enter a number from 1 to 3: ");
pvail = input.nextInt ();

 if  (pvail ==2) {
System.out.println("Congratualions!!! You avail the promo ");
 
 }

 else {
System.out.println("Thank you for joining");
 
 }
  input.close();

}

}

===========================================================



======================
Code: 
=======================

import java.util.Scanner;

public class Test29_Pereda_Challege {

public static void main(String [] args) {
int pvail;
Scanner input = new Scanner(System.in);
System.out.println("Enter your age: ");
pvail = input.nextInt ();
 if  (pvail >=18) {
System.out.println("You are eligible to vote! ");
 
 }
 
 else {
System.out.println("Not eligible to vote!");
 
input.close();
  }
}
}


============================================================



============================
Code: 
==============================
import java.util.Scanner;

public class Test30_Pereda_nestedifelse {

public static void main(String [] args) {


int pvail;
Scanner input = new Scanner (System.in);

System.out.println("Enter a number from 1 to 4: ");
pvail = input.nextInt();


if (pvail == 1) {
System.out.println("Congratulation!!!! Your Discount: 10%");

}

else if (pvail == 2) {
System.out.println("Congratulation!!!! Your Discount: 50%");

}

else if (pvail == 3) {
System.out.println("Sorry you didn't avail the Discount");

}

else if (pvail == 4) {
System.out.println("Congratulation!!!! Your Discount: 20%");

}

else {
System.out.println("The number you entered is invalid. Enter a number from 1 to 4");

}

input.close();


}

}

===================================







Walang komento:

Mag-post ng isang Komento