+ 1

Why doesn't this code do what I want it to do

Note:I am a bit of a beginner so be careful of your comments Why doesn't this code output not a multiple of one point nine only when the input is not a multiple of nine import java.util.Scanner; class code { public static void main(String[] args) {Scanner sc = new Scanner(System.in); double name = sc.nextDouble(); if(name%1.9!=0){System.out.println("not a multiple of one point nine");}else{System.out.println(" multiple of one point nine");}} }

2nd Sep 2023, 5:37 AM
daniel
5 Answers
+ 8
daniel I have attached a working concept of your code. It is easier to debug & understand when presented in the playground. Sometimes copy/paste into Q&A can cause unintended bugs. PS: it is Java, not JS as JaScript has informed you https://code.sololearn.com/cJ1K3rSCgMto/?ref=app
2nd Sep 2023, 6:42 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 7
By the way this is a Java code not JavaScript as in your tag.
2nd Sep 2023, 6:34 AM
JaScript
JaScript - avatar
+ 6
Daniel, that is inaccuracy of a digital numbers calculation. You could that see what happend in this way: System.out.printf("%.19f\n",name%1.9);
2nd Sep 2023, 11:14 AM
JaScript
JaScript - avatar
+ 3
I just thought java was short for javascript
2nd Sep 2023, 10:23 AM
daniel
+ 3
Also Rik I put in there 20.9 and as it didn't work in my code it responded not a multiple of one point nine when1.9×11=20.9 Sorry for making it a year1-3maths class
2nd Sep 2023, 10:27 AM
daniel