Programming Tutorials

By: Paawan Chaudhary in Java Tutorials on 2012-09-19 This Java program defines a class Fraction having data members numerator and denominator. Initializes three objects using different constructors and displays its fractional value.

import java.lang.*; import java.io.*; class Fraction < double numerator,denominator,fraction; Fraction (int a, double b) < numerator=a; denominator=b; fraction=numerator/denominator; System.out.println ("Fraction1 = "+fraction); >Fraction (int x, int y) < numerator=x; denominator=y; fraction=numerator/denominator; System.out.println ("Fraction2 = "+fraction); >Fraction(double m, double n) < numerator=m; denominator=n; fraction=numerator/denominator; System.out.println ("Fraction3 = "+fraction); >> class q3Fraction < public static void main(String args[]) < Fraction f = new Fraction(12,12.3); Fraction f2 = new Fraction(10,12); Fraction f3 = new Fraction(10.5,13.5); >>

Add Comment

Insert Bullet List Please enter at least one item. Insert Numeric List Please enter at least one item. Insert Link Please enter the link of the website Optionally you can add display text Insert Email Please enter the email address Optionally add any display text Insert Image Please enter the link of the image Insert YouTube Video Please enter the link of the video Privacy Policy