Jump to content

Search the Community

Showing results for tags 'java'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • B-Zone
    • Announcements
    • B-Zone Clips
    • Community
    • Forum Suggestions
    • Market
    • Questions and Answers
  • San Andreas Multiplayer
    • RPG.B-Zone.Ro:7777 Roleplay
    • Wiki Website
  • Rage Multiplayer
    • V.B-ZONE.RO
  • B-Zone Online
    • B-Zone Championships
    • B-Zone Clans & Clubs
    • B-Zone Radios
    • Counter-Strike 1.6
    • Discord
    • Metin2
    • Minecraft
  • IT Zone
    • Design
    • Gadgets
    • Programming
    • Software & Hardware
    • Video Games
  • Real life
    • Entertainment
    • History
    • Juridic
    • Lifestyle
    • Politics
    • Sport
    • Vehicles
  • Trash Can
    • Trash Can
  • Very Important Person [VIP]'s [VIP] - Topic
  • zero Limits [zL]'s Topics
  • Safe 4 Family [S4F]'s S4F - Forum
  • Sons of Anarchy MC [SoA]'s Club Matters
  • The Last Kingdom [TLK]'s Topics
  • The First Generation [TFG]'s General
  • United Blood Nation [UBN]'s DSICUTII LIBERE MEMBRII!
  • Wild Balkans [WB]'s Informatii
  • True Silent Aimbot [TSA]'s Topics
  • Alliance [A]'s General
  • Merry Weather [MW]'s Prezenta activitati
  • Merry Weather [MW]'s Anunturi Importante
  • Merry Weather [MW]'s Giveaway
  • Merry Weather [MW]'s Giveaway
  • Dangerous Life [dL]'s General
  • Elite Squad [eS]'s Discord

Calendars

  • Community Calendar
  • Merry Weather [MW]'s Events

Product Groups

There are no results to display.

Categories

  • MODURI
    • CLEO/SAMPFUNCS
    • Vehicles
    • Skins
    • Sounds
    • Effects
    • Weapons
    • Others
    • Modpacks
  • True Silent Aimbot [TSA]'s Files
  • Merry Weather [MW]'s Event

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Website URL


Skype


Steam ID


Discord


Instagram


Location


Hobbies


Real name


RPG1 Nickname


CS 1.6 Nickname

Found 3 results

  1. Azain

    Binary Search What is Binary Search? In computer science, binary search, also known as half-interval search, logarithmic search, or binary chop, is a search algorithm that finds the position of a target value within a sorted array. Binary search compares the target value to the middle element of the array. If they are not equal, the half in which the target cannot lie is eliminated and the search continues on the remaining half, again taking the middle element to compare to the target value, and repeating this until the target value is found. If the search ends with the remaining half being empty, the target is not in the array. Binary search runs in logarithmic time in the worst case, making O(log n) comparisons, where n is the number of elements in the array. Binary search is faster than linear search except for small arrays. However, the array must be sorted first to be able to apply binary search. There are specialized data structures designed for fast searching, such as hash tables, that can be searched more efficiently than binary search. However, binary search can be used to solve a wider range of problems, such as finding the next-smallest or next-largest element in the array relative to the target even if it is absent from the array. How to do Binary Search? Given an array A of n elements with values sorted such that A{0} <= A{1} <= A{2} <= ..... A{n-1} and target value T, the following subroutine uses binary search to find the index of T in A. Set L to 0 and R to n-1. If L > R, the search terminates as unsuccessful. Set m (the position of the middle element) to the floor of L + R / 2 , which is the greatest integer less than or equal to L + R / 2. If A[m] < T, set L to m+1 and go to step 2. If A[m] > T, set R to m-1 and go to step 2. Now A[m] = T, the search is done; return m. Code: package binarysearch; /** * * @author Azain */ public class BinarySearch { /* Recursive method to do binary search on an array, takes an integer array left index, right index and key to find as arguments, array should be sorted otherwise result will not be accurate */ public static int binarySearch(int arr[], int left, int right, int key) { //continue searching for the key until right index is greater then left index if (right >= left) { //middle index of left and right index int mid = left + (right - left) / 2; //Base case, if array middle element is equal to key, the index is returned if (arr[mid] == key) return mid; //when the middle element is greater than the key, search the left if (arr[mid] > key) return binarySearch(arr, left, mid - 1, key); //when the middle element is less than the key, search the right return binarySearch(arr, mid + 1, right, key); } //returning -1, when the key is not found in the array return -1; } public static void main(String[] args) { int arr[] = {1, 2 , 3 , 4, 5, 6, 7, 8 , 9}; int key = 7; int result = binarySearch(arr, 0, arr.length - 1, key); //if key is found if (result == -1) System.out.println(key + " not found!"); else System.out.println(key + " found at index " + result); } } Sources: https://en.wikipedia.org/wiki/Binary_search_algorithm
  2. growndex.

    Cum se conecteaza la o baza de date MySQL cu Java? Java ofera JDBC (Java DataBase Connectivity) ca parte a Java SDK (Software Development Kit). Folosind acest API, este foarte usor sa va conectati la o baza de date relationala. Driverul bazei de date MySQL. Pentru a va putea conecta la o baza de date MySQL, aveti nevoie de driverul JDBC pentru MySQL. Acesta se numeste driverul Connector / J si poate fi descarcat de pe site-ul MySQL. Dupa ce descarcati fisierul ZIP (sau TAR.GZ), extrageti arhiva si copiati fisierul JAR mysql-conector-java-bin.jar la o locatie potrivita. Acest fisier este necesar pentru rularea oricarui cod care utilizeaza driverul JDBC MySQL. Crearea unei baze de date. Urmatoarele creeaza un utilizator numit testuser care se va conecta la baza de date MySQL de la aceeasi masina in care ruleaza (indicata prin gazda locala), folosind parola securepwd. creati utilizator 'testuser' @ 'localhost' identificat prin 'securepwd'; Daca va conectati la o baza de date care ruleaza pe o alta masina (numita remotemc), trebuie sa utilizati urmatoarele (remotemc poate fi un nume de gazdă sau o adresa IP) creati utilizator 'testuser' @ 'remotemc' identificat prin 'securepwd'; Acum, ca numele de utilizator si parola au fost create, trebuie sa acordam acces la baza de date proba creata anterior. acordati-le pe esantion. * la 'testuser' @ 'localhost'; Sau, daca baza de date este la distanta: acordati-le pe esantion. * la 'testuser' @ 'remotemc'; De asemenea, puteti rula urmatoarele comenzi dupa conectare, pentru a va asigura ca toate permisiunile sunt corecte. crea joe joe (id int cheie auto_increment, nume varchar (25)); drop table joe; Configurati calea de clasa Java. Primul pas este sa incarcati driverul bazei de date. Aceasta se face prin invocarea urmatoarelor intr-o locatie potrivita Class.forName ( "com.mysql.jdbc.Driver"); Codul ar putea arunca o exceptie, astfel incat sa il puteti prinde daca intentionati sa o rezolvati (cum ar fi formatarea mesajului de eroare pentru o interfata grafica). incercati Class.forName ("com.mysql.jdbc.Driver"); captura (ClassNotFoundException ex) // utilizati exceptia aici Este foarte frecvent sa invocati acest cod intr-un bloc static din clasa, astfel ca programul nu reuseste imediat daca driverul nu poate fi incarcat. exemplul public de clasa static try Class.forName ("com.mysql.jdbc.Driver"); captura (ClassNotFoundException ex) System.err.println ("Imposibil de incarcat Driverul MySQL"); Conectarea la MySQL Din Java. O modalitate de a crea o conexiune de baze de date este de a utiliza DriverManager. String jdbcUrl = ...; Conexiune con = DriverManager.getConnection (jdbcUrl); Si ce este jdbcUrl? Acesta indica detaliile conexiunii, inclusiv serverul in care se afla baza de date, numele de utilizator si asa mai departe. Iata un exemplu de URL pentru exemplul nostru. String jdbcUrl = "jdbc: mysql: // localhost / sample = user = testuser & password = secretpwd"; Observati ca am inclus toti parametrii necesari pentru conectare, inclusiv numele de gazdă (gazda locala), numele de utilizator și parola. Folosind asta jdbcUrl, aici este un program complet pentru a verifica conectivitatea. exemplul public de clasă static try Class.forName ("com.mysql.jdbc.Driver"); captura (ClassNotFoundException ex) System.err.println ("Imposibil de incarcat Driverul MySQL"); static public void principal (String [] args) arunca Excepție String jdbcUrl = "jdbc: mysql: // localhost / sample = user = testuser & password = securepwd"; Conexiune con = DriverManager.getConnection (jdbcUrl); System.out.println ( "Connected!"); con.close (); Este o idee proasta sa incorporati parola in URL-ul JDBC. Pentru a specifica direct numele de utilizator si parola, puteti folosi urmatoarea optiune de conectare. Stringul jdbcUrl = "jdbc: mysql: // localhost / sample"; incercati (Conexiune con = DriverManager.getConnection (jdbcUrl, "testuser", "securepwd")) Interogarea bazei de date din Java. Acum, cand conexiunea la baza de date este stabilita, sa vedem cum sa efectuam o interogare, cum ar fi interogarea versiunii bazei de date: selectati versiunea (); O interogare este executata in java dupa cum urmeaza. Afirmatie obiect este creat si o interogare este executata folosind executeQuery () metoda care returneaza Setul de rezultate. String queryString = "selectati versiunea ()"; Declaratie stmt = con.createStatement (); Rezultatul rset = stmt.executeQuery (queryString); Imprimati versiunea din Setul de rezultate dupa cum urmeaza. 1 se refera la indexul coloanei in rezultate, începand de la 1. in timp ce (rset.next ()) System.out.println ("Versiune:" + rset.getString (1)); Dupa procesarea rezultatelor, obiectele trebuie inchise. rset.close (); stmt.close (); Si asta acopera tot ceea ce este legat de MySQL de la java si efectuand o interogare simpla. Am explicat pe scurt.. pentru intrebari,probleme[reply,pm].
  3. Azain

    In this Tutorial, I will show you how to perform Linear Search on an Array in Java, I assume that you know the basics of programming and Java language. What is Linear Search? In computer science, a linear search or sequential search is a method for finding an element within a list. It sequentially checks each element of the list until a match is found or the whole list has been searched. Wikipedia Why Linear Search? Linear search is usually very simple to implement, and is practical when the list has only a few elements, or when performing a single search in an un-ordered list. When many values have to be searched in the same list, it often pays to pre-process the list in order to use a faster method. For example, one may sort the list and use binary search, or build an efficient search data structure from it. Should the content of the list change frequently, repeated re-organization may be more trouble than it is worth. As a result, even though in theory other search algorithms may be faster than linear search (for instance binary search), in practice even on medium-sized arrays (around 100 items or less) it might be infeasible to use anything else. On larger arrays, it only makes sense to use other, faster search methods if the data is large enough, because the initial time to prepare (sort) the data is comparable to many linear searches. Wikipedia How to do Linear Search? To do Linear Search on an array, we have to traverse through each element until we have found the element, we were searching for. 1. We'll create a method that takes an integer array and a key as input public static int linearSearch(int arr[], int key) { } 2. Declare two variables, one for storing the index and other for storing the length of the array //In Java, you can get length of an array by typing .length after the name of array int index, length = arr.length; 3. To traverse through each element of the array, we will use a for loop, initialize the index to 0 and keep incrementing by 1, inside the the loop there is a condition if indexth element of array is equal to the key then we'll return the index, otherwise if we have traversed through each element and have not found the key then we'll return -1; for (index = 0; index < arr.length; index++) { if (arr[index] == key) { return index; } } return -1; That's how you can do linear search on an array, following is the full code package com.azain.algorithms; /** * * @author Azain */ public class Search { //Linear Search public static int linearSearch(int arr[], int key) { int index, length = arr.length; for (index = 0; index < arr.length; index++) { if (arr[index] == key) { return index; } } return -1; } }
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.