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); } } |
رد: java program اخي المتحري رائع وننتظر الجديد شـكــ وبارك الله فيك ـــرا لك ... لك مني أجمل تحية . |
رد: java program |
رد: java program شـكــ وبارك الله فيك ـــرا لك ... لك مني أجمل تحية . وهذا اقل مانقدمه للمنتدى |
رد: java program |
الساعة الآن 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
جميع الحقوق محفوظة لمنتديات بني بحير بلقرن