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
- Your name, rating, website address, town, country, state and comment will be publicly displayed if entered.
- Aside from the data entered into these form fields, other stored data about your comment will include:
- Your IP address (not displayed)
- The time/date of your submission (displayed)
- Administrative purposes, should a need to contact you arise.
- To inform you of new comments, should you subscribe to receive notifications.
This policy is subject to change at any time and without notice.
Terms and Conditions
These terms and conditions contain rules about posting comments. By submitting a comment, you are declaring that you agree with these rules:
- Although the administrator will attempt to moderate comments, it is impossible for every comment to have been moderated at any given time.
- You acknowledge that all comments express the views and opinions of the original author and not those of the administrator.
- You agree not to post any material which is knowingly false, obscene, hateful, threatening, harassing or invasive of a person's privacy.
- The administrator has the right to edit, move or remove any comment for any reason and without notice.
Failure to comply with these rules may result in being banned from submitting further comments.
These terms and conditions are subject to change at any time and without notice.