Hi there,
I need help with two methods:
One that does the division between the numbers & one that returns the mod
The program's goal is to do these math operations without using the Big-Int class from java. That's the reason why
I use Array Lists to do it.
import java.util.*;
public class NumberOperations {
public static void main(String[] args){
ArrayList<Integer> biggerNumber = new ArrayList<Integer>();
ArrayList<Integer> smallerNumber = new ArrayList<Integer>();
ArrayList<Integer> operatedNumber = new ArrayList<Integer>();
//just make the program work with big numbers like this.
//thats the whole purpose: handeling big numbers.
String num1 = "123456789101112";
String num2 = "12345678910";
//I thought about storing the numbers backwards into the arraylist
//for a better handeling of the number, feel free to do it as you pleased.
for(int i = num1.length() -1; i>= 0; i --){
char numberChar = num1.charAt(i);
String numberString = ""+numberChar;
biggerNumber.add(Integer.parseInt(numberString));
}
System.out.println("Printing num1: "); // output: [2,1,1,1,0,1,9,8,7,6,5,4,3,2,1]
for(int i = num2.length() -1; i>= 0; i --){
char numberChar = num2.charAt(i);
smallerNumber.add(Integer.parseInt(numberString));
System.out.println("Printing num2: "); //output: [0,1,9,8,7,6,5,4,3,2,1]
// also, assume that the bigger number is always first in parameters, which is num1.
// and smaller number is second in parameters, which is num2.
operatedNumber = devide(biggerNumber, smallerNumber);
System.out.println("Division of numbers: " + operatedNumber); // dont worry about the output from this
// or if the number outputs backwards
operatedNumber = mod(biggerNumber, smallerNumber);
System.out.println("Mod of numbers: " + operatedNumber); // dont worry about the output from this
//Division method should look like this:
public static ArrayList<Integer> devide(ArrayList<Integer> bigger, ArrayList<Integer> smaller){
ArrayList<Integer> devidedNumber = new ArrayList<Integer>();
//
return devidedNumber;
//I also need a method that returns the mod of two numbers.
//This is basically the same as devision() method except that it returns the mod.
public static ArrayList<Integer> mod(ArrayList<Integer> bigger, ArrayList<Integer> smaller){
ArrayList<Integer> modOfNumbers = new ArrayList<Integer>();
return modOfNumbers;
Cheers thanks . any help is appreciated ..