I need an help to figure out what happened. I am an Italian speaker so some variable I have name it in Italian. After some time of no-coding, I've started to code something basic and easy. I made a Class named "Prova" which was a calculator. 4 methods: add, minus, product and divide. First three method had no anomaly, the last one had. I made a runnable class and saw some strange result
Here's the code:
public class Prova {
public int add(int addendo1, int addendo2) {
int res;
res = addendo1+addendo2;
return res;
}
public int minus(int minuendo, int sottraendo) {
int res;
res = minuendo-sottraendo;
return res;
}
public int multiply(int fattore1, int fattore2) {
int res;
res = fattore1*fattore2;
return res;
}
public double divide(int divisore, int dividendo) {
double res;
res = divisore/dividendo;
return res;
}`
Here's the command: public static void main(String[] args) {
Prova somma = new Prova();
System.out.println(somma.add(5, 5)+"\n");
System.out.println(differenza.minus(20, 11)+"\n");
System.out.println(new Prova().product(2, 4)+"\n\n");
System.out.println(new Prova().divide(100, 1)+'\n');
System.out.println(new Prova().divide(100, 2)+'\n');
System.out.println(new Prova().divide(300, 3)+'\n');
System.out.println(new Prova().divide(400, 4)+'\n');
System.out.println(new Prova().divide(500, 5)+'\n');
System.out.println(new Prova().divide(600, 6)+'\n');
}
And here my results:
- 10 //somma.add(5,5)
- 9 //differenza.minus(20,11)
- 8 //multiply(2,4)
- 110.0 //divide(100,1)
- 60.0 //divide(100,2)
- 110.0 //divide(300,3)
- 110.0 //divide(400,4)
- 110.0 //divide(500,5)
- 110.0 //divide(600,6)
Other tries with divide method had given
14/2 = 17.0;
1/1 = 11.0;
2/2 = 11.0;
3/3 = 11.0;
The operator works fine outside my Class Prova.divide(). My question is what happened here? I can't see what I did wronf