You want to calculate the average value of the tag, but do not print the decimal point (Java)
•
Java
See English answer > @ L_ 502_ 0 @ 14
public class NotenDurchschnitt{ public static void main(String[] args){ int note1,note2,note3; double schnitt; note1 = 3; note2 = 4; note3 = 6; schnitt = (note1 + note2 + note3) / 3; System.out.println("Notenschnitt ist: " + schnitt); } }
First, note = mark, Schnitt = average (it's German), so basically I try to print out a similar number (that's why it's not like other problems!!!):
1.0 / 1.5 / 2.0 / 2.5 / 3.0 / 3.5 / 4.0 / 4.5 / 5.0 / 5.5 / 6.0
6 is the best mark and 1 is the worst mark
The thing is that in my program, it only prints 1.0, 2.0
Solution
You are doing integer division, which truncates decimals Try this:
schnitt = (note1 + note2 + note3) / 3.0;
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码