Hi there, I need help with two methods: *One that does the division between the
ID: 3545905 • Letter: H
Question
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 BigInt class from java. Thats the reason why
I use ArrayLists to do it.
Copy the program to your java editor to follow with further instructions.
NOTE: I will fully test the code and then I will award best answer. Do not waste my time or yours. Thanks.
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 biggerNumber: "); // 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);
String numberString = ""+numberChar;
smallerNumber.add(Integer.parseInt(numberString));
}
System.out.println("Printing smallerNumber: "); //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
// or if the number outputs backwards
}
//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;
}
}
Explanation / Answer
humm :) :) :)
Here it is. Seems to be working fine and quickly whatever size of numbers you feed it. Should also deal with negative numbers, infinities and NaN:
Try this ///
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.