The remaining value should be 0.5

Asked 2 years ago, Updated 2 years ago, 21 views

package chap01;

public class Math {

public static void main (String [] args) {
int a,b,c,d,e,f;
double g;


a = 1000;
b = 2000;
c = a+b;
d = a-b;
e = a*b;
f = a/b;
g = a%b;    


System.out.println ("Add = " + c);
System.out.println ("Patch = " + d);
System.out.println ("multiplication = " + e);
System.out.println ("divide = "+f);
System.out.println ("remaining = "+g);

}

}

Add = 3000 Subtraction = -1000 Multiplication = 2000000 Divide = 0 Remaining = 1000

The result is like this Can anyone tell me what's wrong with the rest?

java

2022-09-20 10:56

1 Answers

The remainder of 1000% 2000 is 1000. The value of 0.5 you want is float a = 1000, b = 2000; System.out.println(a/b); You can get it from that.


2022-09-20 10:56

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.