Java Program To Calculate Fraction!!!!

class fraction
{
int num, den, value;
fraction(int n,int d)
{
num=n;
den=d;
}
void calculate()
{
value=(num/den);
}
void display()
{
System.out.println(“The value is=”+value);
}

public static void main(String arg[])
{
fraction f=new fraction(300,10);
f.calculate();
f.display();
}
}

Advertisements

How to Calculate Area Using Java Example

/*

Calculate Circle Area using Java Example

This Calculate Circle Area using Java Example shows how to calculate

area of circle using it’s radius.

*/

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

public class CalculateCircleAreaExample {

public static void main(String[] args) {

int radius = 0;

System.out.println(“Please enter radius of a circle”);

try

{

//get the radius from console

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

radius = Integer.parseInt(br.readLine());

}

//if invalid value was entered

catch(NumberFormatException ne)

{

System.out.println(“Invalid radius value” + ne);

System.exit(0);

}

catch(IOException ioe)

{

System.out.println(“IO Error :” + ioe);

System.exit(0);

}

/*

* Area of a circle is

* pi * r * r

* where r is a radius of a circle.

*/

//NOTE : use Math.PI constant to get value of pi

double area = Math.PI * radius * radius;

System.out.println(“Area of a circle is ” + area);

}

}

/*

Output of Calculate Circle Area using Java Example would be

Please enter radius of a circle

19

Area of a circle is 1134.1149479459152

*/

Hey Guys present u some TrigFun Programs!!!

import javax.swing.*;
public class trigFun
{
 public static void main(String args[])
 {   
    String temp;
    temp=JOptionPane.showInputDialog(null, “Enter an integer to take factorial of”);
    int myFactorial=Integer.parseInt(temp);
    System.out.println(“Factorial of(“+temp+”)=”+factorial(myFactorial));
    temp=JOptionPane.showInputDialog(null, “Enter a radian value”);
    double myRadian=Double.parseDouble(temp);
    System.out.println(“sin(“+myRadian+”)=”+sin(myRadian));
    System.out.println(“cos(“+myRadian+”)=”+cos(myRadian));
    System.out.println(“tan(“+myRadian+”)=”+tan(myRadian));   
 }
 public static double factorial(int n)
 {
    double sum=1;
    for(double i=n; i>0; i–)
    {
        sum=sum*i;
    }
    return sum;
 }
 public static double sin(double radian)//calculated using mclauren series
 {
    int sign;
    if (radian<-3.141592653589793)
     sign=0;
  else
    sign=1;
    if (sign==0)
    {
     while(radian<-3.141592653589793)
     {
      radian=radian+6.283185307179586;
     }
    }
    if (sign==1)
    {
     while(radian>3.141592653589793)
     {
      radian=radian-6.283185307179586;
     }
    }
  
    double result=0;     
    int j=1;                  
    for (double i=1; i<=21;i=i+2)
    {  //21 is a large arbitrary value
     if(j%2==0)
     {
       result=result-1*(pow(radian, i))/((double)(factorial((int)(i))));
     }
     else
     {
      result=result+1*(pow(radian, i))/((double)(factorial((int)(i))));
     }
     j=j+1;
    }
    return result;
 }
 public static double cos(double radian)
 {
    int sign;
    if (radian<0)
     sign=0;
  else
    sign=1;
    if (sign==0)
    {
     while(radian<-3.141592653589793)
     {
      radian=radian+6.283185307179586;
     }
    }
    if (sign==1)
    {
     while(radian>3.141592653589793)
     {
      radian=radian-6.283185307179586;
     }
    }
  
    double result=0;           
    int j=1;                  
    for (double i=0; i<=20;i=i+2)
    {
     if(j%2==0)
     {
       result=result-1*(pow(radian, i))/((double)(factorial((int)(i))));
     }
     else
     {
      result=result+1*(pow(radian, i))/((double)(factorial((int)(i))));
     }
     j=j+1;
    }
    return result;
 }
 public static double tan(double radian)
 {
    int sign;
    if (radian<0)
     sign=0;
  else
    sign=1;
    if (sign==0)
    {
     while(radian<-3.141592653589793)
     {
      radian=radian+6.283185307179586;
     }
    }
    if (sign==1)
    {
     while(radian>3.141592653589793)
     {
      radian=radian-6.283185307179586;
     }
    }
    return sin(radian)/cos(radian);
 }
 public static double pow(double b, double exp)
 { // an incomplete pow function that only calculates correctly for integer exp’s
    double result=1;
    if(exp==0 && b==0)
     return 1./0;
    if(exp==0 && b !=0)
     return 1;    
    for(int i=1; i<=exp; i++)
    {
      result=result*b;
    }
    return result;
 }
}

Embedding an Applet in an HTML Page

You can deploy a simple applet by using the applet tag. Here’s the applet tag for the cartwheeling Duke applet:

<applet code="TumbleItem.class" 
        codebase="examples/"
        archive="tumbleClasses.jar, tumbleImages.jar"
        width="600" height="95">
    <param name="maxwidth" value="120">
    <param name="nimgs" value="17">
    <param name="offset" value="-57">
    <param name="img" value="images/tumble">

Your browser is completely ignoring the <applet> tag!
</applet>

www.glutenfreedetroitmetro.com


First things first. Thank you all for reading, supporting, and helping with Gluten Free Detroit Metro. Being a Celiac or gluten-free isn’t an easy journey (at first) and the fellowship this community has is wonderful. We are elated to be a part of it.

If you are not familiar there are several ways you can “keep up” with Gluten Free Detroit Metro. One is by being our Facebook Fan. You may also check us out on Twitter if that is your networking media of choice. Lastly, on the right side of our website there is a subscribe box where our information will come straight to your inbox. GFDM encourages you to use one of these methods so you do not miss out on information or local events coming soon.

Give me the good stuff! After days of entries and great comments a winner was randomly picked. I do believe…

View original post 73 more words

Enter your Email ID

Sewing Friends Wearables

Colette Patterns is a nice site with patterns, tutorials, a blog, and a forum. The patterns seem pretty popular in the various sewing blogs that I’ve read (I haven’t tried any myself), and they have a charming vintage vibe to them. But the topic of this post is Snippets, their weekly email of sewing tips. I signed up for it relatively recently, and I like it — the emails are helpful little nuggets of information. Here are some of the Snippets that I’ve received:

  • Sewing with plaids
  • How to sew velvet (and other napped fabrics)
  • 6 ways to get more out of your fabric stash
  • Before you start
  • 3 ways to improve your lighting

To learn more about Snippets and see a sample email, visit the Snippets subscription page.

Snippets

View original post

Square root program in java

import javax.swing.*;
public class sqrt
{
public static void main(String args[])
{
String tempString=JOptionPane.showInputDialog(“Enter a positive number”);
double number=Double.parseDouble(tempString);
System.out.println(“Square root of ” + number+”=”+sqrt(number));
}
public static double sqrt(double number)
{ //square root Babylonian method

double estimate=number;
double divisor=2;
//below 100 is arbitrary, for very small decimals  i values must be large
for(int i=0; i<100; i++)
{
estimate=number/divisor;
estimate=(estimate+divisor)/2; //find average estimate & divisor
divisor=estimate;
}
return estimate;
}
}

Square root program in java

import javax.swing.*;
public class sqrt
{
public static void main(String args[])
{
String tempString=JOptionPane.showInputDialog(“Enter a positive number”);
double number=Double.parseDouble(tempString);
System.out.println(“Square root of ” + number+”=”+sqrt(number));
}
public static double sqrt(double number)
{ //square root Babylonian method

double estimate=number;
double divisor=2;
//below 100 is arbitrary, for very small decimals i values must be large
for(int i=0; i<100; i++)
{
estimate=number/divisor;
estimate=(estimate+divisor)/2; //find average estimate & divisor
divisor=estimate;
}
return estimate;
}
}