Skip to content

Instantly share code, notes, and snippets.

@spukles
Created September 21, 2022 17:45
Show Gist options
  • Save spukles/be5cad28483bb8d7ecec85f7f16e0465 to your computer and use it in GitHub Desktop.
Save spukles/be5cad28483bb8d7ecec85f7f16e0465 to your computer and use it in GitHub Desktop.
import java.util.Scanner;
public class FractiontoDecimal{
//Main Method
public static void main (String [] args){
//Create a Scanner Object
Scanner in = new Scanner(System.in);
//Receive Inputs
System.out.println("Numerator:");
int num = in.nextInt();
System.out.println("Denominator:");
//Compute Int, quotient, num, den
int den = in.nextInt();
//User inputs 1/0, 2/0, 3/0 etecetera
if( den == 0)
{
System.out.println("Division by zero does not work");
}
else
{
double quotient = (double)num / den;
System.out.printf("%d / %d converted to a decimal is %f.", num, den, quotient);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment