Sie sind auf Seite 1von 6

BISECTOARE TANGENTA COPAC LISTA BAZA DE DATE BISECTOARE

package prinbisectie; public class PrInBisectie { static static static static static double f(double x){return -7*x+3;} double a=-10; double b=10; double sigma=0.0001; int nr_it=1000;

static void getRad(double a,double b){ double c=(a+b)/2.0; if(b-a<sigma) System.out.printf("Solutia este: %.10f\n", c); else if(--nr_it==0)System.out.println("Depasire nr iteratii"); else if(f(a)*f(c)<0) getRad(a,c); else getRad(c,b); } public static void main(String[] args) { if (a>b)System.out.println("Inteval incorect"); else if(f(a)*f(b)>=0)System.out.println("Sol nu este in interval"); else getRad(a,b); } } TANGENTA package mettangentei; public class MetTangentei { static double a=-1; static double b=5; static double x00=4; static double sigma=0.000001; static int nr_it=100; static double f(double x){return Math.pow(x, 2)-2;} static double fp(double x){return 2*x; } static void Sol(double a,double b){ double x0=x00; double x1=x0-f(x0)/fp(x0); int count=0; for(;;) { if(Math.pow((x1-x0),2)<sigma){ System.out.println("Sol este: "+x1); break; } x0=x1; x1=x0-f(x0)/fp(x0); if(++count==nr_it) { System.out.println("Depasire nr iterartii"); break; } }

} public static void main(String[] args) { if (a>b)System.out.println("Inteval incorect"); else if(f(a)*f(b)>=0)System.out.println("Sol nu este in interval"); else Sol(a,b); } } COPAC package tree; import java.util.ArrayList; import java.util.HashMap; class Tree<T> { private final T head; private final ArrayList<Tree<T>> leafs = new ArrayList<>(); private Tree<T> parent = null; private HashMap<T, Tree<T>> locate = new HashMap<>(); public Tree(T head) { this.head = head; locate.put(head, this); } public void addLeaf(T root, T leaf) { if (locate.containsKey(root)) { locate.get(root).addLeaf(leaf); } else { addLeaf(root).addLeaf(leaf); } } public Tree<T> addLeaf(T leaf) { Tree<T> t = new Tree<>(leaf); leafs.add(t); t.parent = this; t.locate = this.locate; locate.put(leaf, t); return t; } public Tree<T> setAsParent(T parentRoot) { Tree<T> t = new Tree<>(parentRoot); t.leafs.add(this); this.parent = t; t.locate = this.locate; t.locate.put(head, this); t.locate.put(parentRoot, t); return t; } public T getHead() { return head; } public Tree<T> getParent() { return parent;

} @Override public String toString() { return printTree(0); } private static final int indent = 2; public String printTree(int increment) { String s ; String inc = ""; for (int i = 0; i < increment; ++i) { inc = inc + " "; } s = inc + head; for (Tree<T> child : leafs) { s += "\n" + child.printTree(increment + indent); } return s; } public void searchTree(T elements,String s) { s+=" "+head; if (head.toString().equals( elements.toString())) System.out.println("Drum: "+s); for (Tree<T> child : leafs) child.searchTree( elements,s); } } public class apelareTree{ public static void main(String[] args) { Tree root = new Tree("sasa"); Tree copil1 = new Tree("stai"); Tree copil2 = new Tree("jos"); Tree copil3 = new Tree("asa1"); Tree copil4 = new Tree("asa2"); Tree copil5 = new Tree("asa3"); Tree copil6 = new Tree("asa4"); Tree copil7 = new Tree("asa3"); Tree t =new Tree(root); t.setAsParent(root) ; t.addLeaf(copil1); t.addLeaf(copil2); t.addLeaf(copil1,copil3); t.addLeaf(copil1,copil4); t.addLeaf(copil1,copil5); t.addLeaf(copil2,copil6); t.addLeaf(copil2,copil7); Tree caut = new Tree("asa3"); System.out.println("Arbore:"); System.out.println(t.printTree(3)); t.searchTree(caut,""); /*

Tree t =new Tree("sasa"); t.setAsParent("sasa"); t.addLeaf("child1","child3"); t.addLeaf("child2","child4"); t.addLeaf("child1","child5"); t.addLeaf("child1","child6"); t.addLeaf("child3","child7"); t.addLeaf("child7","child312"); t.addLeaf("child8","child7"); t.addLeaf("child666"); Tree caut = new Tree("child7"); System.out.println("Arbore:"); System.out.println(t.printTree(3)); String s=""; t.searchTree(caut,s); */

} }

LISTA

package sortarelistamulticriteriu; import java.util.*; public class SortareListaMulticriteriu { public static void main(String[] args) { Elev nameArray[] = { new Elev("Afsd", "Bmith",10), new Elev("Afsd", "Amith",15), new Elev("Barl", "ba",20), new Elev("Earl", "Na",20), new Elev("Feff", "Smith",50), new Elev("Feff", "Smith",20), new Elev("Com", "Rich",30) }; List<Elev> listaDeSortat = Arrays.asList(nameArray); Collections.sort(listaDeSortat); System.out.println(listaDeSortat); } public static class Elev implements Comparable<Elev> { private final String nume, prenume; private final int varsta; public Elev(String numep, String prenumep, int varstap) {

if (numep == null || prenumep == null|| varstap<=0||numep == "" || prenu mep == "" ){ System.out.println("Date incorecte"); throw new NullPointerException(); } this.nume = numep; this.prenume = prenumep; this.varsta=varstap; } public String nume() { return nume; } public String prenume() { return prenume; } public int varsta() { return varsta; } @Override public String toString() { return nume + " " + prenume+" "+varsta; } @Override public int compareTo(Elev n) { int comparison = nume.compareTo(n.nume); if (comparison != 0) return comparison; comparison = prenume.compareTo(n.prenume); if (comparison != 0) return comparison; comparison = Integer.toString(varsta).compareTo(Integer.toString(n.varsta )); return comparison;

} } }

BAZE DE DATE

package oraclethinconnection; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.sql.*; public class OracleThinConnection{ public static void main(String args[]){ try { Class.forName("oracle.jdbc.driver.OracleDriver"); // connect using Thin driver Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1 521:xe","system","radu"); //System.out.println("Connected Successfully To Oracle");

Statement stmt = con.createStatement(); ResultSet rs=null; try{ rs = stmt.executeQuery("SELECT * FROM HR.EMPLOYEES "); }catch(SQLException rr){ rr.printStackTrace(); System.out.println("eroare select"); } ResultSetMetaData rsmd = rs.getMetaData(); //System.out.println("querying SELECT * FROM XXX"); int columnsNumber = rsmd.getColumnCount(); File file = new File("Exemplu_Select.csv"); FileWriter fstream = new FileWriter(file); BufferedWriter out = new BufferedWriter(fstream); for (int i = 1; i <= columnsNumber; i++) out.write(rsmd.getColumnNa me(i)+","); out.newLine(); while (rs.next()) { for (int i = 1; i <= columnsNumber; i++){ if(i==1)out.newLine(); if (i > 1) { //System.out.print(", "); out.write(" ");} String columnValue = rs.getString(i); //System.out.print(columnValue + " " + rsmd.getColumnName(i)); out.write(columnValue + " ," );//+ rsmd.getColumnName(i)); } //System.out.println(""); } stmt.close(); rs.close(); con.close(); out.close(); fstream.close(); } catch(Exception ex){ System.out.println("Conectiune nereusita"); ex.printStackTrace(); } } }

Das könnte Ihnen auch gefallen