Tuesday, July 12, 2011

2 part sum of three number divide by fourth number

This java program is able to calculate result in decimal value, you only have to change 8 line of previous program from(int A,B,C,D,total;) to (double A,B,C,D,total;).
In this program we take four input number from user -A, B, C, D.
hear A, B, C are added and divided by D,this is the hole detail of program. 


source code
  1. import java.io.*;
  2. class sum_of_three_no_divide_by_fourth_no
  3. {
  4. public static void main(String[] args)throws IOException
  5. {
  6. InputStreamReader ir=new InputStreamReader(System.in);
  7. BufferedReader br=new BufferedReader(ir);
  8. double A,B,C,D,total;
  9. System.out.println("Eter no1");
  10. A=Double.parseDouble(br.readLine());
  11. System.out.println("Eter no2");
  12. B=Double.parseDouble(br.readLine());
  13. System.out.println("Eter no3");
  14. C=Double.parseDouble(br.readLine());
  15. System.out.println("Eter no4");
  16. D=Double.parseDouble(br.readLine());
  17. total=(A+B+C)/D;
  18. System.out.println("Total="+total);
  19. }
  20. }

No comments:

Post a Comment