منتديات بني بحير بلقرن

منتديات بني بحير بلقرن (http://www.binybohair.com/vb/)
-   الحاسب الآلي (http://www.binybohair.com/vb/f19/)
-   -   java program (http://www.binybohair.com/vb/binybohair2324/)

المتحري 03-01-2009 02:55 PM

java program
 
السلام عليكم ورحمة الله وبركاته
هذه بعض الا كواد للجافا تستخدم في برنامج الجافا التعليمي:
import java.util.*;
class BinaryTree
{
BinaryTree left;
BinaryTree right;
int value;
public BinaryTree (int v)
{
value=v;
}
public void insert(int v)
{
if(v<value)
{
if(left==null)
left=new BinaryTree(v);
else
left.insert(v);
}
if(v>value)
{
if(right==null)
right=new BinaryTree(v);
else
right.insert(v);
}
}
public void display()
{
System.out.println(value);
System.out.println(left.value);
System.out.println(right.value);
}
public static void main (String args[])
{
BinaryTree b=new BinaryTree(50);
b.insert(20);
b.insert(30);
b.insert(60);
b.display();
}
}

----------------------------------------------------------------------------------------------------------------------------
/*Factorial of a Number
Recursive Function
*/
import javax.swing.*;
class Factorial
{
int num;
public void EnterValue()
{
String str;
str=JOptionPane.showInputDialog(null,"Enter a Number to find Factorial: ");
num=Integer.parseInt(str);
}

public int factorial(int n)
{
if (n == 1)
return 1;

return n * factorial(n-1); //Recursive Function
}
public static void main(String args[])
{
int result;
Factorial f=new Factorial();
f.EnterValue();
result=f.factorial(f.num);
System.out.println("The Factorial of a Number is: "+result);
}
}
----------------------------------------------------------------------------------------------------------------------------
/*Power of a Number
Recursive Function
*/
import javax.swing.*;
class Power
{
static double n ,x;
public void EnterValue()
{
String str1,str2;
str1=JOptionPane.showInputDialog(null,"Enter a Base Value to find Power: ");
x=Double.parseDouble(str1);
str2=JOptionPane.showInputDialog(null,"Enter a Power Value to find Power: ");
n=Double.parseDouble(str2);
}

public static double power(double x,double n)
{
if(n<0)
{
JOptionPane.showMessageDialog(null,"Enter only positive number: ");
System.exit(0);
}
if (n == 0)
return 1.0;

return (x * power(x,(n-1))); //Recursive Function
}
public static void main(String args[])
{
double result;
Power p=new Power();
p.EnterValue();
result=Power.power(x,n);
JOptionPane.showMessageDialog(null,"The Power of a number is: "+result);
}
}

----------------------------------------------------------------------------------------------------------------------------
import javax.swing.*;
class Search
{
int n,x;
int a[ ]=new int[20];


void getData()
{
String s=JOptionPane.showInputDialog(null,"Number of Elements: ");
n=Integer.parseInt(s);

JOptionPane.showMessageDialog(null,"Enter the Elements: ");

for(int i=0;i<n;i++)
{
s=JOptionPane.showInputDialog(null,"Element= ");

a[i]=Integer.parseInt(s);

}

System.out.println("Enter the Element to Search: ");
s=JOptionPane.showInputDialog(null,"Element to search: ");
x=Integer.parseInt(s);

}

int binSearch(int low,int high)
{
int mid;

if(low>high)
return -1;

mid=(low+high)/2;

if(x==a[mid])
return mid;

else if(x<a[mid])
return binSearch(low,mid-1);
else
return binSearch(mid+1,high);

//return x==mid?mid:x<a[mid]?binSearch(low,mid-1):binSearch(mid+1,high);
}
}
class Binary_Search
{
public static void main(String args[])
{
int m;

Search s=new Search();

s.getData();

int found=s.binSearch(0,5);

if(found==-1)

JOptionPane.showMessageDialog(null,"Not Found: ");

else

JOptionPane.showMessageDialog(null,"Found at Location: "+found);

}


}

ابورزان 03-01-2009 05:41 PM

رد: java program
 
اخي المتحري رائع وننتظر الجديد

شـكــ وبارك الله فيك ـــرا لك ... لك مني أجمل تحية .

عاشق الرعد 03-01-2009 06:10 PM

رد: java program
 
http://img24.imageshack.us/img24/4295/59439347.gif

المتحري 03-01-2009 09:06 PM

رد: java program
 
شـكــ وبارك الله فيك ـــرا لك ... لك مني أجمل تحية .
وهذا اقل مانقدمه للمنتدى

المعلم 03-01-2009 09:12 PM

رد: java program
 
http://img516.imageshack.us/img516/9759/shokrancc1.jpg


الساعة الآن 12:29 PM

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Content Relevant URLs by vBSEO 3.6.0 PL2
ارشفة ودعم SALEM ALSHMRANI
F.T.G.Y 3.0 BY: D-sAb.NeT © 2011
جميع الحقوق محفوظة لمنتديات بني بحير بلقرن


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75