Page 237 - IT-802_class_12
P. 237

if-else statements can also be nested – you can have another if-else statement within an outer if or else statement.
            The example below is a nested if.

            if (percentage >= 40)
            {

             System.out.println(“pASSED”);
            if (percentage>= 75)
            {

            System.out.println(“With Distinction!”);
            }

            }
            else

            {
            Let us create a program.

            public class percentageCalculator {
                public static void main(String [] args){

                    int total_marks=400;
                    double marks_obtained=364;

                    double percentage;
                    percentage = (marks_obtained/total_marks)*100;
                    System.out.println(“1st Student`s percentage =” +percentage);

                    if (percentage >= 40)

            {
            System.out.println(“pASSED”);
            if (percentage>= 75)
            {

            System.out.println(“With Distinction!”);
            }}
            else

            {
                {
                }

                }
                  System.out.println(“FAiLED”);
            }


            }



                                                                               Fundamentals of Java Programming  235
   232   233   234   235   236   237   238   239   240   241   242