-
Need help on Fraction
hi, I'm new to java and I need some idea on how can I do this program.
For example:
numerator: 7
denominator: 49
fraction type: proper fraction //the class will identify whether the fraction is proper, improper or mixed fractions
decimal equiv: 0.14286
Can anyone help me?
Thanks!
-
Look at the / and % operators, especially when applied to int with an int result.
-
Well ..jus see this
i wud say the solution is as simple as that ... but ..i m not sure abt the input .. how wud u input the numbers ?? jus numerator and denominator? then this shud work fine
import java.util.*;
public class fractions {
/**
* @author javamadd
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int num,deno;
Scanner scanboy = new Scanner(System.in);
System.out.println("Enter num");
num = scanboy.nextInt();
System.out.println("Enter deno");
deno = scanboy.nextInt();
System.out.println("the fraction is " + num +"/" +deno++);
if ( num > deno)
System.out.println("Its an Improper fraction");
else
System.out.println("Its a Proper Fraction");
}
}