This java program is not able to calculate result in decimal value, and if you provide that type of input it give wrong answer.
For Ex- n1=3, n2=2, n3=3 and n4=3 then answer (Total=2) which is wrong right answer is (2.6666).
In 2nd part program we provide how to get rid from this error.
source code
For Ex- n1=3, n2=2, n3=3 and n4=3 then answer (Total=2) which is wrong right answer is (2.6666).
In 2nd part program we provide how to get rid from this error.
source code
- import java.io.*;
- class sum_of_three_no_divide_by_fourth_no
- {
- public static void main(String[] args)throws IOException
- {
- InputStreamReader ir=new InputStreamReader(System.in);
- BufferedReader br=new BufferedReader(ir);
- int A,B,C,D,total;
- System.out.println("Eter no1");
- A=Integer.parseInt(br.readLine());
- System.out.println("Eter no2");
- B=Integer.parseInt(br.readLine());
- System.out.println("Eter no3");
- C=Integer.parseInt(br.readLine());
- System.out.println("Eter no4");
- D=Integer.parseInt(br.readLine());
- total=(A+B+C)/D;
- System.out.println("Total="+total);
- }
- }
No comments:
Post a Comment