Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
1Activity
0 of .
Results for:
No results containing your search query
P. 1
Java Programs I-IV(1)

Java Programs I-IV(1)

Ratings: (0)|Views: 22|Likes:
Published by sownat
anna univ 3rd year java programs
anna univ 3rd year java programs

More info:

Published by: sownat on Aug 27, 2010
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less

08/27/2010

pdf

text

original

 
PROGRAM:
import java.io.*;/**<code> c1</code> is a class which is used to calculateAddition,Subtraction,Multiplicationand Division with the GCD value*/class c1{int a,b;/**finding addition@param num1 numerator1 value@param den1 denominator1 value@param num2 numerator2 value@param den2 denominator2 value*/ public void add(int num1,int num2,int den1,int den2){int num3,den3;num1=num1*den2;num2=num2*den1;num3=num1+num2;den3=den1*den2;int d=gcd(num3,den3);int snum=(int)num3/d;int sden=(int)num3/d;System.out.println("The addition is:"+sum+"/"+sden);}/**Finding Subtraction@param num1 numerator1 value@param den1 denominator1 value@param num2 numerator2 value@param den2 denomionator2 value*/ public void sub(int num1,int den1,int num2,int den2){int num3,den3;num1=num1*den2;num2=num2*den1;num3=num1-num2;den3=den1*den2;int d=gcd(num3,den3);int snum=(int)num3/d;int sden=(int)den3/d;System.out.println("The Subtraction:"+snum+"/"+sden);
GKMCET40708104042
 
}/** Finding Multiplication@param num1 numerator1 value@param den1 denominator1 value@param num2 numerator2 value@param den2 denomionator2 value*/ public void mul(int num1,int den1,int num2,int den2){int num3,den3;num3=num1*num2;den3=den1*den2;int d=gcd(num3,den3);int snum=(int)num3/d;int sden=(int)den3/d;System.out.println("The Multiplication is:"+snum+"/"+sden);}/** Finding Division@param num1 numerator1 value@param den1 denominator1 value@param num2 numerator2 value@param den2 denomionator2 value*/ public void div(int num1,int den1,int num2,int den2){int num3,den3,temp;temp=num2;num2=den2;den2=temp;num3=num1*num2;den3=den1*den2;int snum=(int)num3/d;int sden=(int)den3/d;System.out.println("The Division is:"+snum+"/"+sden);}/**FInding Greatest Common Divisor @param num3 numerator3 value@param den3 denominator3 value@return the GCD value will be returned*/ public int gcd(int num3,int den3){int c;
GKMCET40708104042
 
while(true){c=num3%den3;if(c==0) break;num3=den3;den3=c;}return(den3);}}/**<code>rational</code> is a class which is used to performaddition,subtraction,multiplicationand division of rational number.@author MING 28-07-10@version version 5.0*/ public class rational{ public static void main(String args[])throws Exception{int num1,den1,num2,den2;DataInputStream obj=new DataInputStream(System.in);try{System.out.println("Enter the numerator1:");num1=Integer.parseInt(readLine());System.out.println("Enter the denominator1:");den1=Integer.parseInt(readLine());System.out.println("Enter the numerator2:");num1=Integer.parseInt(readLine());System.out.println("Enter the denominator2:");den2=Integer.parseInt(readLine());c1 m=new c1();m.add(num1,den1,num2,den2);m.sub(num1,den1,num2,den2);m.mul(num1,den1,num2,den2);m.div(num1,den1,num2,den2);}catch(Exception e){}}}
GKMCET40708104042

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->