Created
September 21, 2022 17:45
-
-
Save spukles/be5cad28483bb8d7ecec85f7f16e0465 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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