Page 120 - CA_Blue( J )_Class10
P. 120

System.out.println(a);
                  }
                  else
                  {
                      System.out.println(b);
                  }
                                                 Start



                                                a=5, b=2





                                               Condition:           true
                                                 if(a>b)                           Print a


                                             false

                                                Print b



                                                  End



                             To input the cost price and selling price of an item. If the selling price is more than cost price, then
                Program 3
                             print "The item was sold in profit". Also print the profit amount. And if the cost price is more than
                             the selling price, then print "The item was sold in loss". Also print the loss amount.

                 1  import java.util.*;

                 2  class profit_loss
                 3      {
                 4          public static void main ()

                 5          {

                 6              Scanner sc= new Scanner (System.in);
                 7              double cp,sp,p,l;
                 8              System.out.print("Enter the Cost Price : ");

                 9              cp = sc.nextDouble();
                10              System.out.print("Enter the Selling Price : ");

                11              sp = sc.nextDouble();
                12              if(sp>cp)

                13              {
                14                  p = sp - cp;

                15                  System.out.println("The item was sold in profit. ");





                118118  Touchpad Computer Applications-X
   115   116   117   118   119   120   121   122   123   124   125