0

How to add two numbers without using any operator in java...

like 5+7=12;//it is ignore. add(5,7)=12;

16th Mar 2017, 2:52 AM
Nazmul
Nazmul - avatar
3 odpowiedzi
+ 2
Write a method public static int add(int x, int y){ int z=x+y; return z; } Then you can just call it with your argument of the numbers you want added. examples: add(5,7); returns 12 add(5,3); returns 8 add(3,7); returns 10 System.out.println(add(2,6));
16th Mar 2017, 3:56 AM
LordHill
LordHill - avatar
0
Also made another method. it is crude, but it will add(5,7) without using operators, using 2 for loops. check my codes to see it run or here is a rough breakdown of it static List<String> temp = new ArrayList<String>(); public static int add(int x, int y){ temp.clear(); for(int i=0;i<x;i++){ temp.add("A"); } for(int i=0;i<y;i++){ temp.add("A"); } int z = temp.size(); return z; } System.out.println(add(5,7)); System.out.println(add(6,4));
16th Mar 2017, 4:13 AM
LordHill
LordHill - avatar
0
thank
18th Mar 2017, 1:18 AM
Nazmul
Nazmul - avatar