Anonymous user
Ethiopian multiplication: Difference between revisions
→{{header|Java}}: I can;t believe it went that long with no one catching this error, added negative check to first version
(Added Pascal) |
(→{{header|Java}}: I can;t believe it went that long with no one catching this error, added negative check to first version) |
||
Line 1,074:
import java.util.Map;
import java.util.Scanner;
public class Mult
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
Line 1,080:
int second = sc.nextInt();
if(first < 0){
Map <Integer, Integer> columns = new HashMap <Integer, Integer>();▼
first = -first;
second = -second;
}
columns.put(first, second);
do{
first =
second =
columns.put(first, second);
}while(first != 1);
int sum = 0;
for(Map.Entry
if(!isEven(entry.getKey())){
sum += entry.getValue();
Line 1,106 ⟶ 1,111:
public static boolean isEven(int num){
return (num & 1) == 0;
}
}</lang>
Line 1,133 ⟶ 1,138:
/**
* This method is an improved version that will use
* ethiopian styled multiplication,
*
* @param a Any integer.
* @param b Any integer.
|