This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// These two need to be declared outside the try/catch | |
// so that they can be closed in the finally block. | |
HttpURLConnection urlConnection = null; | |
BufferedReader reader = null; | |
// Will contain the raw JSON response as a string. | |
String forecastJsonStr = null; | |
try { | |
// Construct the URL for the OpenWeatherMap query |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.oracle.java; | |
public class BinarySearchTree { | |
private int treeHeight(Node root) { | |
if (root == null) return 0; | |
return (1 + Math.max(treeHeight(root.left), treeHeight(root.right))); | |
} | |
private boolean isBalancedNaive(Node node) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class App { | |
public static void main(String[] args) { | |
int x = 8; | |
int[] arr = {-3, -2, 1, 7, 8, 11, 12, 21}; | |
for (int i = 0; i < arr.length; i++) { | |
int a = arr[i]; | |
int b = x - a; | |
if (b <= arr[arr.length - 1]) { | |
int result = divideAndConquer(arr, b, i + 1, arr.length - 1); | |
if (result != -1) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class App { | |
public static void main(String[] args) { | |
int[] prices = {5, 8, 6, 1, 4, 5}; | |
int count = 0; | |
if (prices.length >= 1 && prices.length <= 5000) { | |
for (int i = 0; i < prices.length; i++) { | |
if (i <= prices.length - 2) { | |
for (int j = i + 1; j < prices.length; j++) { | |
if (j <= prices.length - 1) { | |
if (prices[i] > prices[j]) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Summation { | |
public static void main(String[] args) throws IOException { | |
// Read & write data from file. | |
Scanner in = new Scanner(System.in); | |
final String fileName = System.getenv("OUTPUT_PATH"); | |
BufferedWriter bw = new BufferedWriter(new FileWriter(fileName)); | |
int res; | |
int _numbers_size = 0; | |
_numbers_size = Integer.parseInt( in .nextLine().trim()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <vector> | |
#include <list> | |
#include <map> | |
#include <set> | |
#include <queue> | |
#include <deque> | |
#include <stack> | |
#include <bitset> | |
#include <algorithm> | |
#include <functional> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int main(){ | |
node * root = NULL; | |
int a[100005],K,i = 0,j = 0, _element, present; | |
scanf("%d",&K); | |
for( j = 0; j < K;j++ ) { | |
scanf("%d",&a[i++]); | |
} | |
for( i = 0; i < K;i++ ){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.java; | |
import java.io.FileInputStream; | |
import java.io.FileNotFoundException; | |
import java.io.IOException; | |
import java.io.InputStream; | |
/** | |
* Exception handling | |
* <a href="http://www.journaldev.com/1696/exception-handling-in-java">Exception Handling in Java</a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.logging.Logger; | |
/** | |
* Thread join | |
* <a href="http://www.journaldev.com/1024/java-thread-join-example">Java Thread Join</a> | |
*/ | |
class ThreadJoin { | |
static Logger logger = Logger.getLogger(App.class.getSimpleName()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.w3c.dom.Document; | |
import org.w3c.dom.Node; | |
import org.w3c.dom.NodeList; | |
import org.xml.sax.InputSource; | |
import org.xml.sax.SAXException; | |
import javax.xml.parsers.DocumentBuilder; | |
import javax.xml.parsers.DocumentBuilderFactory; | |
import javax.xml.parsers.ParserConfigurationException; | |
import java.io.IOException; |
OlderNewer