Computer engineering - C# php asp .Net SAP SQL: jcreator
Showing posts with label jcreator. Show all posts
Showing posts with label jcreator. Show all posts

Wednesday, March 26, 2008

Machine Epsilon

Machine epsilon is the smallest number when it is added to 1 your computer assumes it 1 briefely. It depends the physical features of your computer. After this definition let us create the pseudocode of a program that computes your machines' epsilons.




epsilon=1
DO
IF(1+epsilon<=1) EXIT
epsilon=epsilon/2
END DO
epsilon=epsilon*2

The code above is the pseudocode of a machine epsilon algorythm. I guess you know about pseudocode :) If you do not know do not be sorry since it is nothing :P It is a description of an algorythm that is language independent.YOu just write on what you think to do. That is it!

Now let me give you the Java code of that algorythm and the output of it.

import javax.swing.JOptionPane;

public class epsilon{
public static void main(String args[]){
double epsilon = 1.0;
for(int i=1; i<100000; i++){

if(epsilon+1.0<=1.0){
break;
}
else{
epsilon=epsilon/2.0;
}
}
epsilon=2*epsilon;
JOptionPane.showMessageDialog(null,"The epsilon of the machine is:"+epsilon);
}
}

Since i have explained each line of a java code example i think you can understand the steps and pseudocode helps you in this issue as well.

So my output is in the figure below. But do not be confused if you have not got the same output since it depends the physical features of your PC!



I will keep giving some java examples as well. Using Java in mathematic will suprise you or mathematics will suprise you ;)

Sunday, March 2, 2008

Where to Execute Our Codes?

Although most of object oriented programming languages are mostly platform dependent we generally use soma programms to execute them. For instance JCreator is mostly known one taht you can access from http://www.jcreator.com.
And the other program is Microsoft Visual Studio. By it you can work on many languages. One of them is the newest C# which i will show examples later.

In this article i will give an example code in Java again.

import javax.swing.JOptionPane;
public class hmwrk4_1 {
public static void main (String[] args) {
System.out.println("Feet Meters\n---- ------");
for(double i=1.0; i<=10.0; i++) {
double meter=footToMeter(i);
if(i==10.0) {
System.out.println(i+" "+meter); }
else System.out.println(i+" "+meter); }
System.out.println("\nMeters Feet\n------ ----");
for(double i=20.0; i<=65.0; i+=5){
double foot=meterToFoot(i);
String s1=String.valueOf(foot);
if(foot>99.999){
String s2=s1.substring(0,7);
System.out.println(i+" "+s2); }
else{ String s2=s1.substring(0,6); System.out.println(i+" "+s2); } } }
public static double footToMeter(double foot){
double meter=0.305*foot;
return meter;}
public static double meterToFoot(double meter){
double foot=meter/0.305; return foot;}}

In comment you can write on what the program does. I will add it on the article later

Friday, February 29, 2008

Introduction to Programming in Java

I will explain programming in Java on an example. In this example we will calculate the roots of an equation whose solution is not a complex root.Our program will give an output if the root of the equation is complex as COMPLEX ROOT!!! User will enter the coefficients of the equation.

Let us start to examine the code of the program:

import javax.swing.JOptionPane; --> This code is to activate JOptionPane function of Java.

public class hmwrk2_1{ ---> Firstly we create our class which our object will be included

public static void main (String[] args) { --->We are starting to write the main function of our code

int a, b, c; ---> Now we declare our variables which i have explained in Programming Languages article

a=Integer.parseInt(JOptionPane.showInputDialog(null,"ax^2 + bx + c \n please enter the coefficient a:")); ---> We are assigning variable a to the value which user enters




b=Integer.parseInt(JOptionPane.showInputDialog(null,"ax^2 + bx + c \n please enter the coefficient b:")); --->we are assigning the value which user enters to the variable b again

c=Integer.parseInt(JOptionPane.showInputDialog(null,"ax^2 + bx + c \n please enter the constant c:")); --->same process as above.

double x1,x2; ---> We are declaring 2 double values for roots of the equation

double delta=(b*b)-(4*a*c); --->We are declaring double delta and setting it to a equation in formula

if(delta<0){> If delta value that we calculated by the values user have entered is smaller than zero we we get the warning complex root!!!

JOptionPane.showMessageDialog(null,"COMPLEX ROOT!!!"); }


else if (delta==0){ --->If delta value equals to zero
x1 = x2 = -b/(2*a); ---> We calculate the roots as in formula.

JOptionPane.showMessageDialog(null,"root= "+x1);---> And printing one of them to the screen


}

else { ---> If the value of delta is bigger than zero
x1=(-b+(Math.sqrt(delta)))/(2*a); ---> We set x1 and x2 variables as in formula.

x2=(-b-(Math.sqrt(delta)))/(2*a);

JOptionPane.showMessageDialog(null,"root1= "+x1+"\nroot2= "+x2); ---> And printing both of them to the screen


}
}
}