import java.io.File; import java.io.IOException; public class CreateFile { public static void main(String[] args) { try { File myObj = new File("filename.txt"); if (myObj.createNewFile()) { System.out.println("File created: " + myObj.getName()); } else { System.out.println("...
This example shows how you can use if..else to "open a door" if the user enters the correct code:ExampleGet your own Java Server int doorCode = 1337; if (doorCode == 1337) { System.out.println("Correct code. The door is now open."); } else { System.out.println("Wrong code....
From https://php.net/manual/en/function.get-headers.php#112652: functionget_http_response_code($theURL){$headers=get_headers($theURL);returnsubstr($headers[0],9,3);}if(intval(get_http_response_code('filename.jpg'))<400){echo"file was found";}else{echo"no file found";} It shows ...
SyntaxGet your own Java Server if(condition1){// block of code to be executed if condition1 is true}elseif(condition2){// block of code to be executed if the condition1 is false and condition2 is true}else{// block of code to be executed if the condition1 is false and condition2...
Java print(0) print(1) count = 2 def fibonacci(prev1, prev2): global count if count <= 19: newFibo = prev1 + prev2 print(newFibo) prev2 = prev1 prev1 = newFibo count += 1 fibonacci(prev1, prev2) else: return fibonacci(1,0) #Python Python result: 0 1...
C Java class Graph: def __init__(self, size): self.size = size self.edges = [] # For storing edges as (u, v, weight) self.vertex_data = [''] * size # Store vertex names def add_edge(self, u, v, weight): if 0 <= u < self.size and 0 <= v < self.size:...
We can also use else if to check more than one condition, so that we get more than two outcomes.Python JavaScript Java C++ age = 15 print('Age: ' + str(age)) if age < 13: print('You are a child') elif age < 20: print('You are a teenager') else: print('You are an ...
The way the code above first removes a value and then inserts it somewhere else is intuitive. It is how you would do Insertion Sort physically with a hand of cards for example. If low value cards are sorted to the left, you pick up a new unsorted card, and insert it in the correct...
import java.io.File; import java.io.IOException; public class CreateFileDir { public static void main(String[] args) { try { File myObj = new File("C:\\Users\\MyName\\filename.txt"); if (myObj.createNewFile()) { System.out.println("File created: " + myObj.getName()); System...
import java.io.File; public class DeleteFolder { public static void main(String[] args) { File myObj = new File("C:\\Users\\MyName\\Test"); if (myObj.delete()) { System.out.println("Deleted the folder: " + myObj.getName()); } else { System.out.println("Failed to delete the...