Page 87 - CA_Blue( J )_Class10
P. 87

The InputStreamReader class provides different methods to input values of different data types. For example,
                 To accept a word or a sentence:
                    String w=br.readLine();
                 To accept an Integer:
                 a.  Integer of size 1 byte
                    byte b=Byte.parseByte(br.readLine());
                 b.  Integer of size 2 bytes
                    short s=Short.parseShort(br.readLine());
                 c.  Integer of size 4 bytes
                    int n=Integer.parseInt(br.readLine());
                 d.  Integer of size 8 bytes
                    long l=Long.parseLong(br.readLine());
                 To accept a real number:
                 a.  Real number of size 4 bytes
                    float f=Float.parseFloat(br.readLine());
                 b.  Real number of size 8 bytes
                    double d=Double.parseDouble(br.readLine());
                 To accept a character
                    char c=(char)(br.read());
                               To input brand name and the cost price of a shirt. Suppose the selling price is 50% more than cost
                  Program 6
                               price. Calculate the profit and print details using InputStreamReader class.

                    1  import java.io.*;
                    2  class inputstreamreader

                    3  {
                    4      public static void main()throws IOException

                    5      {
                    6          BufferedReader br= new BufferedReader(new InputStreamReader(System.in));

                    7          String bn;
                    8          double cp,sp,p,pp;
                    9          System.out.print("Enter the name of the brand : ");

                  10           bn=br.readLine();

                  11           System.out.print("Enter the cost price of the shirt : ");
                  12           cp = Double.parseDouble(br.readLine());
                  13           sp=cp+(0.5*cp);

                  14           p=sp-cp;
                  15           System.out.println(" Brand name         : "+bn);

                  16           System.out.println(" Cost price         : "+cp);
                  17           System.out.println(" Selling Price      : "+sp);

                  18           System.out.println(" Profit made         : "+p);
                  19       }

                  20   }



                                                                                                                       85
                                                                                                         Input in Java   85
   82   83   84   85   86   87   88   89   90   91   92