3
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 of all note = mark, schnitt = average (it's German) so basically I try to print out a number which is like that(this is why it's not like the other questions!!!):

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.

The thing is in my program it only would print 1.0, 2.0,...

Robin
  • 31
  • 3
  • The cause of the problem is the same. The part "(note1 + note2 + note3) / 3" is an integer division just like in the other question. The same solution also applies: you need to make of your arguments a float or double before doing the division, so e.g."(note1 + note2 + note3) / 3.0" would work. – GeertPt Feb 14 '19 at 16:26

1 Answers1

6

You're doing integer division, which truncates decimals. Try this instead:

schnitt = (note1 + note2 + note3) / 3.0;
Óscar López
  • 232,561
  • 37
  • 312
  • 386