I don't really see a sign that there's error in my code, but when i run it I see these.
----------TESTING CONSTRUCTORS--------------
Exception in thread "main" java.lang.ArithmeticException: / by
zero
at
hw2.Fraction.greatestCommonDivisor(Fraction.java:224)
at
hw2.Fraction.reduceToLowestTerms(Fraction.java:209)
at hw2.Fraction.(Fraction.java:44)
at hw2.Fraction.main(Fraction.java:285
What does this mean? I'm currently coding a java program on Fractions.
1. The thing I'm confused are I definitely know there's no error in greatestCommonDivisor and reducedToLowestTerms as those were the codes provided by the instructors and were never modified. (main function as well)
for , i've called reducedToLowestTerms in function public Fraction(initial numerator, initial denominator)
public Fraction(int initialNumerator, int
initialDenominator)
{
if (initialDenominator == 0)
{
initialDenominator = 1;
}
adjustSigns();
reduceToLowestTerms();
}
EDIT: Here's a given code of GCD
private int greatestCommonDivisor(int integerOne, int
integerTwo)
{
int result;
if (integerOne % integerTwo ==
0)
result =
integerTwo;
else
result =
greatestCommonDivisor(integerTwo, integerOne % integerTwo);
return result;
} // end greatestCommonDivisor
You are getting this error because somehow when your code is running for some input value, it has come across an operation where you are trying to divide a number by 0, resulting in DivideByZeroArithmeticException.
My suspection is that in the greatestCommonDivisor(), you might have misplaced the if/else conditions, I have tried to replicate the issue in my local environment but could not. The GCD function seems to be working fine.

In case you are still getting the error, kindly provide me the full code, and I will look into it.
I don't really see a sign that there's error in my code, but when i run...
******Java Programming Hi guys, I really need you help. I created a code for my java course, but it keep giving me error messages. Majority of my code is fine but some keep display error on my console. I was hoping someone could pin points the problem. .There are three classes with the testCenter class being the main class. In the following is the assignment, and the bottom is my code. Please help! Assignment: Concepts: GUI User Design Graphics Deployment...
Lab 1.java only Goal: This lab will give you experience with defining and using classes and fields, and with conditionals and recursive functions. Getting Started --------------- Read the Fraction.java class into a text editor and compile it filling in the command javac -g Fraction.java. The program should compile without errors. In a shell window, run the program using "java Fraction". The program should run, although it will print fractions in a non-reduced form, like 12/20. Part I: Constructors (1 point)...
Hello, so I need someone to look over this code and see if im on the right path. I feel like im missing something. Here is the assignment: Create a class called Slogans. This class will extend the Thread class. This thread will read from a file several quotes that are on each line. It will pick a quote randomly and display it to the console. It will change quotes every 7 seconds. This will be updated in the final...
Creating a calculator for my CS1 class and my code was able to run but it crashes near the end. As far as I know, the error means that it's retrieving "null" from the variable but I haven't seen that kind of error from this kind of situation. I would appreciate any help. I'm just starting up in Java so I apologize if this is a silly question. Thank you! ``` ----jGRASP exec: java CS1Calculator ------------ Welcome to the CS1...
What is wrong with my code, when I pass in 4 It will not run, without the 4 it will run, but throw and error. I am getting the error required: no arguments found: int reason: actual and formal argument lists differ in length where T is a type-variable: T extends Object declared in class LinkedDropOutStack public class Help { /** * Program entry point for drop-out stack testing. * @param args Argument list. */ public static void main(String[] args)...
I need help with the following Java code Consider a class Fraction of fractions. Each fraction is signed and has a numerator and a denominator that are integers. Your class should be able to add, subtract, multiply, and divide two fractions. These methods should have a fraction as a parameter and should return the result of the operation as a fraction. The class should also be able to find the reciprocal of a fraction, compare two fractions, decide whether two...
Having trouble with my code, it keeps giving me an error every time I run it. Can someone please help me understand what I'm doing wrong? *********CODE*************** // Java program to read the file contents, sort it and output the sorted content to another file import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileInputStream; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collections; public class Datasort { public static void main(String[] args) throws IOException { File fin = new File("input.txt");...
My code is not doing what I want it to do and I can't seem to figure out why it's not working. I commented some of the code to give some context to what I'm trying to do. Can someone check to see where my code is off. I'm assuming that I didn't use the counters properly or I'm using the pointers incorrectly. I can only use pointers to do this by the way. Code: #include <iostream> using namespace std;...
I need help with my code when I run my code running the wrong thing like this After downSize() words.length=60003 wordCount=60003 vowelCount=206728 this is my code here import java.io.*; import java.util.*; public class Project02 { static final int INITIAL_CAPACITY = 10; public static void main (String[] args) throws Exception { // ALWAYS TEST FIRST TO VERIFY USER PUT REQUIRED INPUT FILE NAME ON THE COMMAND LINE if (args.length < 1 ) ...
How do I correct this error in my code?
When it got to the file type I can only go "null" from a certain
point and I'm wondering how to correct this error.
Also can I get a word document on this coding strategy for this
problem? How much of this am I doing correctly?
The original problem description:
Create a program that provides a listing of all the files in a
directory. The program should be a Java application...