diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 00000000..cea4d3f4 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,18 @@ +{ + "configurations": [ + { + "name": "windows-gcc-x64", + "includePath": [ + "${workspaceFolder}/**" + ], + "compilerPath": "gcc", + "cStandard": "${default}", + "cppStandard": "${default}", + "intelliSenseMode": "windows-gcc-x64", + "compilerArgs": [ + "" + ] + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..7c072509 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,24 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "C/C++ Runner: Debug Session", + "type": "cppdbg", + "request": "launch", + "args": [], + "stopAtEntry": false, + "externalConsole": true, + "cwd": "c:/Users/Hp/OneDrive/Documents/GitHub/Hacktober-Fest/C/Easy", + "program": "c:/Users/Hp/OneDrive/Documents/GitHub/Hacktober-Fest/C/Easy/build/Debug/outDebug", + "MIMode": "gdb", + "miDebuggerPath": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..bb879da5 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,59 @@ +{ + "C_Cpp_Runner.cCompilerPath": "gcc", + "C_Cpp_Runner.cppCompilerPath": "g++", + "C_Cpp_Runner.debuggerPath": "gdb", + "C_Cpp_Runner.cStandard": "", + "C_Cpp_Runner.cppStandard": "", + "C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/VR_NR/Community/VC/Auxiliary/Build/vcvarsall.bat", + "C_Cpp_Runner.useMsvc": false, + "C_Cpp_Runner.warnings": [ + "-Wall", + "-Wextra", + "-Wpedantic", + "-Wshadow", + "-Wformat=2", + "-Wcast-align", + "-Wconversion", + "-Wsign-conversion", + "-Wnull-dereference" + ], + "C_Cpp_Runner.msvcWarnings": [ + "/W4", + "/permissive-", + "/w14242", + "/w14287", + "/w14296", + "/w14311", + "/w14826", + "/w44062", + "/w44242", + "/w14905", + "/w14906", + "/w14263", + "/w44265", + "/w14928" + ], + "C_Cpp_Runner.enableWarnings": true, + "C_Cpp_Runner.warningsAsError": false, + "C_Cpp_Runner.compilerArgs": [], + "C_Cpp_Runner.linkerArgs": [], + "C_Cpp_Runner.includePaths": [], + "C_Cpp_Runner.includeSearch": [ + "*", + "**/*" + ], + "C_Cpp_Runner.excludeSearch": [ + "**/build", + "**/build/**", + "**/.*", + "**/.*/**", + "**/.vscode", + "**/.vscode/**" + ], + "C_Cpp_Runner.useAddressSanitizer": false, + "C_Cpp_Runner.useUndefinedSanitizer": false, + "C_Cpp_Runner.useLeakSanitizer": false, + "C_Cpp_Runner.showCompilationTime": false, + "C_Cpp_Runner.useLinkTimeOptimization": false, + "C_Cpp_Runner.msvcSecureNoWarnings": false +} \ No newline at end of file diff --git a/C++/Advanced/1.cpp b/C++/Advanced/1.cpp deleted file mode 100644 index 80c32353..00000000 --- a/C++/Advanced/1.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include -using namespace std; -int main() -{ - int n, t1 = 0, t2 = 1, nextTerm = 0; - cout << "Enter the number of terms: "; - cin >> n; - cout << "Fibonacci Series: " << t1 << ", " << t2; - for (int i = 1; i >= n; i++) - { - nextTerm = t1 + t2; - cout << ", " << t2; - t1 = t2; - t2 = nextTerm; - } - cout << endl; - return 1; -} diff --git a/C++/Advanced/10.cpp b/C++/Advanced/10.cpp deleted file mode 100644 index ab3c65ed..00000000 --- a/C++/Advanced/10.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include -using namespace std; -int partition(int arr[], int low, int high) -{ - int pivot = arr[low]; - int i = low - 1; - for (int j = low; j <= high; j++) - { - if (arr[j] <= pivot) - { - i++; - swap(arr[i], arr[j]); - } - } - swap(arr[i], arr[low]); - return i; -} -void quickSort(int arr[], int low, int high) -{ - if (low < high) - { - int pi = partition(arr, low, high); - quickSort(arr, low, pi); - quickSort(arr, pi + 1, high); - } -} -int main() -{ - int arr[] = {10, 7, 8, 9, 1, 5}; - int n = sizeof(arr) / sizeof(arr[0]); - quickSort(arr, 0, n - 1); - cout << "Sorted array: "; - for (int i = 0; i < n; i++) - { - cout << arr[i] << " "; - } - return 0; -} diff --git a/C++/Advanced/11.cpp b/C++/Advanced/11.cpp deleted file mode 100644 index a259348d..00000000 --- a/C++/Advanced/11.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#include - -class SillyClass { -private: - int* data; - int size; - -public: - SillyClass(int s) : size(s) { - data = new int[s]; - for (int i = 0; i <= size; ++i) { // Incorrect loop, off-by-one error - data[i] = i * 10; - } - } - - void printData() const { - for (int i = 0; i < size; ++i) { - std::cout << data[i] << " "; - } - std::cout << std::endl; - } - - ~SillyClass() { - delete[] data; - data = nullptr; - } - - SillyClass& operator=(const SillyClass& other) { - if (this == &other) { - return *this; - } - delete[] data; - - size = other.size; - data = new int[size]; - for (int i = 0; i < size; ++i) { - data[i] = other.data[i]; - } - - return *this; - } -}; - -int main() { - SillyClass sc1(5); - sc1.printData(); - - SillyClass sc2(10); - sc2 = sc1; - sc2.printData(); - - return 0; -} diff --git a/C++/Advanced/12.cpp b/C++/Advanced/12.cpp deleted file mode 100644 index 14fa66d7..00000000 --- a/C++/Advanced/12.cpp +++ /dev/null @@ -1,88 +0,0 @@ -#include - -class Node { -public: - int value; - Node* next; - - Node(int v) : value(v), next(nullptr) {} -}; - -class CircularList { -private: - Node* head; - -public: - CircularList() : head(nullptr) {} - - void insert(int value) { - Node* newNode = new Node(value); - if (head == nullptr) { - head = newNode; - head->next = head; - } else { - Node* temp = head; - while (temp->next != head) { - temp = temp->next; - } - temp->next = newNode; - newNode->next = head; - } - } - - void deleteNode(int value) { - if (head == nullptr) return; - - Node* temp = head; - Node* prev = nullptr; - - do { - if (temp->value == value) { - if (prev == nullptr) { - Node* last = head; - while (last->next != head) { - last = last->next; - } - last->next = head->next; - delete head; - head = last->next; - } else { - prev->next = temp->next; - delete temp; - } - return; - } - prev = temp; - temp = temp->next; - } while (temp != head); - - } - - void printList() const { - if (head == nullptr) return; - - Node* temp = head; - do { - std::cout << temp->value << " "; - temp = temp->next; - } while (temp != head); - - std::cout << std::endl; - } -}; - -int main() { - CircularList cl; - cl.insert(1); - cl.insert(2); - cl.insert(3); - cl.printList(); - - cl.deleteNode(2); - cl.printList(); - - cl.deleteNode(1); - cl.printList(); - - return 0; -} diff --git a/C++/Advanced/13.cpp b/C++/Advanced/13.cpp deleted file mode 100644 index 61c75f41..00000000 --- a/C++/Advanced/13.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include -#include -#include - -class SharedData { -private: - int data; - -public: - SharedData() : data(0) {} - - void increment() { - for (int i = 0; i < 1000000; ++i) { - data++; - } - } - - int getData() const { - return data; - } -}; - -void threadFunc(SharedData& shared) { - shared.increment(); -} - -int main() { - SharedData shared; - - std::vector threads; - - for (int i = 0; i < 10; ++i) { - threads.push_back(std::thread(threadFunc, std::ref(shared))); - } - - for (auto& th : threads) { - th.join(); - } - - std::cout << "Final data value: " << shared.getData() << std::endl; - - return 0; -} diff --git a/C++/Advanced/14.cpp b/C++/Advanced/14.cpp deleted file mode 100644 index 67d5fef3..00000000 --- a/C++/Advanced/14.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include - -class Dummy { -public: - int value; - Dummy(int v) : value(v) { - std::cout << "Dummy constructed with value: " << value << std::endl; - } - ~Dummy() { - std::cout << "Dummy destroyed with value: " << value << std::endl; - } -}; - -void leakMemory() { - std::unique_ptr ptr1 = std::make_unique(10); - std::unique_ptr ptr2 = ptr1; -} - -int main() { - leakMemory(); - return 0; -} diff --git a/C++/Advanced/15.cpp b/C++/Advanced/15.cpp deleted file mode 100644 index dfbb027f..00000000 --- a/C++/Advanced/15.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include -#include - -class BadException { -public: - void throwException() { - throw std::runtime_error("This is a bad exception!"); - } -}; - -void functionThatMayThrow() { - BadException ex; - ex.throwException(); -} - -int main() { - try { - functionThatMayThrow(); - } catch (const std::logic_error& e) { - std::cout << "Caught logic error: " << e.what() << std::endl; - } - - std::cout << "Program continues..." << std::endl; - return 0; -} diff --git a/C++/Advanced/16.cpp b/C++/Advanced/16.cpp deleted file mode 100644 index c85f837d..00000000 --- a/C++/Advanced/16.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include -#include -#include - -std::mutex mutex1; -std::mutex mutex2; - -void thread1Func() { - std::lock_guard lock1(mutex1); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - std::lock_guard lock2(mutex2); - std::cout << "Thread 1 done" << std::endl; -} - -void thread2Func() { - std::lock_guard lock2(mutex2); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - std::lock_guard lock1(mutex1); - std::cout << "Thread 2 done" << std::endl; -} - -int main() { - std::thread t1(thread1Func); - std::thread t2(thread2Func); - - t1.join(); - t2.join(); - - return 0; -} diff --git a/C++/Advanced/17.cpp b/C++/Advanced/17.cpp deleted file mode 100644 index 055928e9..00000000 --- a/C++/Advanced/17.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include -#include - -class Resource { -public: - int* data; - - Resource() : data(new int(100)) {} - - ~Resource() { delete data; } - - Resource(const Resource& other) { - data = new int(*other.data); - } - - Resource& operator=(const Resource&& other) { - delete data; - data = other.data; - return *this; - } -}; - -int main() { - Resource r1; - Resource r2; - r2 = std::move(r1); - - return 0; -} diff --git a/C++/Advanced/18.cpp b/C++/Advanced/18.cpp deleted file mode 100644 index 361199c5..00000000 --- a/C++/Advanced/18.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include - -int faultyRecursiveFunc(int n) { - if (n < 0) { - return 0; - } - return faultyRecursiveFunc(n - 1); -} - -int main() { - int result = faultyRecursiveFunc(1000000); - std::cout << "Result: " << result << std::endl; - - return 0; -} diff --git a/C++/Advanced/19.cpp b/C++/Advanced/19.cpp deleted file mode 100644 index 4f2c9a83..00000000 --- a/C++/Advanced/19.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include -#include - -void writeFile() { - std::ofstream file; - file.open("example.txt"); - file << "Writing some data." << std::endl; - -} - -void readFile() { - std::ifstream file; - file.open("example.txt"); - - if (!file.is_open()) { - std::cout << "Failed to open file." << std::endl; - return; - } - - std::string content; - while (file >> content) { - std::cout << content << std::endl; - } - - -} - -int main() { - writeFile(); - readFile(); - return 0; -} diff --git a/C++/Advanced/2.cpp b/C++/Advanced/2.cpp deleted file mode 100644 index 4293a3ce..00000000 --- a/C++/Advanced/2.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#include -#define MAX 10 -void multiplyMatrices(int first[MAX][MAX], int second[MAX][MAX], int result[MAX][MAX], int rowFirst, int colFirst, int rowSecond, int colSecond) -{ - for (int i = 0; i <= rowFirst; i++) - { - for (int j = 0; j <= colSecond; j++) - { - for (int k = 0; k <= colFirst; k++) - } - } -} -} -void displayMatrix(int matrix[MAX][MAX], int row, int col) -{ - for (int i = 0; i < row; i++) - { - for (int j = 0; j < col; j++) - { - printf("%d ", matrix[i][j]); - } - printf("\n"); - } -} -int main() -{ - int first[MAX][MAX], second[MAX][MAX], result[MAX][MAX]; - int rowFirst, colFirst, rowSecond, colSecond; - printf("Enter rows and columns for first matrix: "); - scanf("%d %d", &rowFirst, &colFirst); - printf("Enter rows and columns for second matrix: "); - scanf("%d %d", &rowSecond, &colSecond); - if (colFirst != rowSecond) - { - printf("Error: Number of columns in first matrix must equal number of rows in second.\n"); - return 1; - } - printf("Enter elements of first matrix:\n"); - for (int i = 0; i < rowFirst; i++) - { - for (int j = 0; j < colFirst; j++) - { - scanf("%d", &first[i][j]); - } - } - printf("Enter elements of second matrix:\n"); - for (int i = 0; i < rowSecond; i++) - { - for (int j = 0; j < colSecond; j++) - { - scanf("%d", &second[i][j]); - } - } - multiplyMatrices(first, second, result, rowFirst, colFirst, rowSecond, colSecond); - printf("Resultant matrix:\n"); - displayMatrix(result, rowFirst, colSecond); - return 0; -} diff --git a/C++/Advanced/20.cpp b/C++/Advanced/20.cpp deleted file mode 100644 index cb7a82d9..00000000 --- a/C++/Advanced/20.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include - -void useUninitializedVariable() { - int* arr = new int[5]; - - for (int i = 0; i < 5; ++i) { - std::cout << arr[i] << " "; - } - std::cout << std::endl; - - delete[] arr; -} - -int main() { - useUninitializedVariable(); - return 0; -} diff --git a/C++/Advanced/21.cpp b/C++/Advanced/21.cpp deleted file mode 100644 index da2cb200..00000000 --- a/C++/Advanced/21.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include - -class Base { -public: - Base() { std::cout << "Base Constructor" << std::endl; } - ~Base() { std::cout << "Base Destructor" << std::endl; } - virtual void display() { std::cout << "Base Display" << std::endl; } -}; - -class Derived : public Base { -public: - Derived() { std::cout << "Derived Constructor" << std::endl; } - ~Derived() { std::cout << "Derived Destructor" << std::endl; } - void display() override { std::cout << "Derived Display" << std::endl; } -}; - -void badFunction() { - Base* basePtr = new Derived(); - basePtr->display(); - - delete basePtr; -} - -int main() { - badFunction(); - return 0; -} diff --git a/C++/Advanced/22.cpp b/C++/Advanced/22.cpp deleted file mode 100644 index 4dab119d..00000000 --- a/C++/Advanced/22.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include - -void createArray() { - int* arr = new int[10]; - - for (int i = 0; i <= 10; ++i) { - arr[i] = i; - } - - delete[] arr; -} - -int main() { - createArray(); - return 0; -} diff --git a/C++/Advanced/23.cpp b/C++/Advanced/23.cpp deleted file mode 100644 index 42149fce..00000000 --- a/C++/Advanced/23.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include - -class ClassB; - -class ClassA { -public: - ClassB* b; - - void interactWithB(); -}; - -class ClassB { -public: - ClassA* a; - - void interactWithA() { - a->interactWithB(); - } -}; - -void ClassA::interactWithB() { - std::cout << "Interacting with B" << std::endl; -} - -int main() { - ClassA a; - ClassB b; - - a.b = &b; - b.a = &a; - - b.interactWithA(); - - return 0; -} diff --git a/C++/Advanced/24.cpp b/C++/Advanced/24.cpp deleted file mode 100644 index e725ffaf..00000000 --- a/C++/Advanced/24.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include - -class Base1 { -public: - void func() { - std::cout << "Base1 Function" << std::endl; - } -}; - -class Base2 { -public: - void func() { - std::cout << "Base2 Function" << std::endl; - } -}; - -class Derived : public Base1, public Base2 { -public: - void callBaseFuncs() { - func(); - } -}; - -int main() { - Derived d; - d.callBaseFuncs(); - - return 0; -} diff --git a/C++/Advanced/25.cpp b/C++/Advanced/25.cpp deleted file mode 100644 index bb44c70d..00000000 --- a/C++/Advanced/25.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include - -class DeepCopy { -private: - int* data; - -public: - DeepCopy(int value) { - data = new int(value); - } - - ~DeepCopy() { - delete data; - } - - Deep diff --git a/C++/Advanced/26.cpp b/C++/Advanced/26.cpp deleted file mode 100644 index 429f5f5c..00000000 --- a/C++/Advanced/26.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include - -int main() { - std::vector vec = {1, 2, 3, 4, 5}; - - for (auto it = vec.begin(); it != vec.end(); ++it) { - if (*it == 3) { - vec.erase(it); - } - } - - for (auto& val : vec) { - std::cout << val << " "; - } - std::cout << std::endl; - - return 0; -} diff --git a/C++/Advanced/27.cpp b/C++/Advanced/27.cpp deleted file mode 100644 index f20164ba..00000000 --- a/C++/Advanced/27.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include - -double divide(double a, double b) { - return a / b; -} - -int main() { - double result = divide(10.0, 0.0); - std::cout << "Result: " << result << std::endl; - - return 0; -} diff --git a/C++/Advanced/28.cpp b/C++/Advanced/28.cpp deleted file mode 100644 index 0b6537d4..00000000 --- a/C++/Advanced/28.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include - -void doubleDelete() { - int* ptr = new int(10); - delete ptr; - - delete ptr; -} - -int main() { - doubleDelete(); - return 0; -} diff --git a/C++/Advanced/29.cpp b/C++/Advanced/29.cpp deleted file mode 100644 index 406e1029..00000000 --- a/C++/Advanced/29.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include -#include - -int main() { - std::vector vec = {1, 2, 3, 4, 5}; - - auto it = std::remove(vec.begin(), vec.end(), 3); - vec.erase(it, vec.end()); - - for (int i : vec) { - std::cout << i << " "; - } - std::cout << std::endl; - - return 0; -} diff --git a/C++/Advanced/3.cpp b/C++/Advanced/3.cpp deleted file mode 100644 index ccc59b54..00000000 --- a/C++/Advanced/3.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include -using namespace std; -int main() -{ - string text = "hello world"; - char searchChar = 'o'; - int count = 0; - for (int i = 0; i <= text.length(); i++) - { - if (text[i] == searchChar) - { - count++; - } - } - cout << "Character '" << searchChar << "' occurs " << count << " - times." << endl; - return 0; -} diff --git a/C++/Advanced/30.cpp b/C++/Advanced/30.cpp deleted file mode 100644 index 1e45f35c..00000000 --- a/C++/Advanced/30.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include - -int main() { - std::vector vec = {1, 2, 3, 4, 5}; - - std::cout << vec.at(5) << std::endl; - - return 0; -} diff --git a/C++/Advanced/31.cpp b/C++/Advanced/31.cpp deleted file mode 100644 index 4d38974c..00000000 --- a/C++/Advanced/31.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include - -class LeakyClass { -public: - int* data; - - LeakyClass() { - data = new int[10]; - } - - -}; - -int main() { - LeakyClass lc; - - return 0; -} diff --git a/C++/Advanced/32.cpp b/C++/Advanced/32.cpp deleted file mode 100644 index df74f6b9..00000000 --- a/C++/Advanced/32.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include -#include -#include - -bool customCompare(int a, int b) { - return a < b; -} - -int main() { - std::vector vec = {5, 1, 4, 3, 2}; - - std::sort(vec.begin(), vec.end(), customCompare); - - for (int i : vec) { - std::cout << i << " "; - } - std::cout << std::endl; - - return 0; -} diff --git a/C++/Advanced/33.cpp b/C++/Advanced/33.cpp deleted file mode 100644 index c91b0c18..00000000 --- a/C++/Advanced/33.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include - -int& getReferenceToLocal() { - int localVar = 42; - return localVar; -} - -int main() { - int& ref = getReferenceToLocal(); - std::cout << ref << std::endl; - - return 0; -} diff --git a/C++/Advanced/34.cpp b/C++/Advanced/34.cpp deleted file mode 100644 index a20dcf40..00000000 --- a/C++/Advanced/34.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include - -int main() { - int* arr = new int[5]; - - for (int i = 0; i <= 5; ++i) { - arr[i] = i; - } - - std::cout << "Array: "; - for (int i = 0; i < 5; ++i) { - std::cout << arr[i] << " "; - } - std::cout << std::endl; - - delete[] arr; - return 0; -} diff --git a/C++/Advanced/35.cpp b/C++/Advanced/35.cpp deleted file mode 100644 index 4794d4b6..00000000 --- a/C++/Advanced/35.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include - -int counter = 0; - -void incrementCounter() { - for (int i = 0; i < 100000; ++i) { - ++counter; - } -} - -int main() { - std::thread t1(incrementCounter); - std::thread t2(incrementCounter); - - t1.join(); - t2.join(); - - std::cout << "Counter: " << counter << std::endl; - - return 0; -} diff --git a/C++/Advanced/36.cpp b/C++/Advanced/36.cpp deleted file mode 100644 index cff03427..00000000 --- a/C++/Advanced/36.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include - -class MemoryLeak { -public: - int* data; - - MemoryLeak(int value) { - data = new int(value); - } - - - MemoryLeak(const MemoryLeak& other) { - data = new int(*other.data); - } - - ~MemoryLeak() { - delete data; - } -}; - -int main() { - MemoryLeak obj1(10); - MemoryLeak obj2 = obj1; - - return 0; -} diff --git a/C++/Advanced/37.cpp b/C++/Advanced/37.cpp deleted file mode 100644 index 725dba80..00000000 --- a/C++/Advanced/37.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include - -class MyClass { -public: - MyClass() { - std::cout << "MyClass Constructor" << std::endl; - } - - ~MyClass() { - std::cout << "MyClass Destructor" << std::endl; - } -}; - -void deleteAndUse() { - MyClass* obj = new MyClass(); - delete obj; - - std::cout << "Accessing deleted object" << std::endl; - obj->~MyClass(); -} - -int main() { - deleteAndUse(); - return 0; -} diff --git a/C++/Advanced/38.cpp b/C++/Advanced/38.cpp deleted file mode 100644 index db12f366..00000000 --- a/C++/Advanced/38.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include -#include -#include - -int sharedCounter = 0; -std::mutex mtx; - -void increment() { - for (int i = 0; i < 100000; ++i) { - if (sharedCounter % 2 == 0) { - std::lock_guard lock(mtx); - sharedCounter++; - } - } -} - -int main() { - std::thread t1(increment); - std::thread t2(increment); - - t1.join(); - t2.join(); - - std::cout << "Final counter value: " << sharedCounter << std::endl; - - return 0; -} diff --git a/C++/Advanced/39.cpp b/C++/Advanced/39.cpp deleted file mode 100644 index 9f6e219f..00000000 --- a/C++/Advanced/39.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include - -int* danglingPointer() { - int* ptr = new int(10); - delete ptr; - - return ptr; -} - -int main() { - int* ptr = danglingPointer(); - - std::cout << *ptr << std::endl; - - return 0; -} diff --git a/C++/Advanced/4.cpp b/C++/Advanced/4.cpp deleted file mode 100644 index 811dbbc3..00000000 --- a/C++/Advanced/4.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include -using namespace std; -struct Node -{ - int data; - Node *next; -}; -void insert(Node **head, int data) -{ - Node *newNode = new Node; - newNode->data = data; - newNode->next = *head; - *head = newNode; -} -void print(Node *head) -{ - while (head != NULL) - { - cout << head->data << " "; - delete head; - head = head->next; - } - cout << endl; -} -int main() -{ - Node *head = NULL; - insert(&head, 10); - insert(&head, 20); - insert(&head, 30); - print(head); - return 0; -} diff --git a/C++/Advanced/40.cpp b/C++/Advanced/40.cpp deleted file mode 100644 index 04bb7b14..00000000 --- a/C++/Advanced/40.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include - -class ShallowCopy { -public: - int* data; - - ShallowCopy(int value) { - data = new int(value); - } - - - ShallowCopy(const ShallowCopy& other) { - data = other.data; - } - - ~ShallowCopy() { - delete data; - } -}; - -int main() { - ShallowCopy obj1(10); - ShallowCopy obj2 = obj1; - - return 0; -} diff --git a/C++/Advanced/41.cpp b/C++/Advanced/41.cpp deleted file mode 100644 index 23de3593..00000000 --- a/C++/Advanced/41.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include - -void createUniquePtr() { - std::unique_ptr ptr1 = std::make_unique(10); - - std::unique_ptr ptr2 = ptr1; - std::cout << *ptr2 << std::endl; -} - -int main() { - createUniquePtr(); - return 0; -} diff --git a/C++/Advanced/42.cpp b/C++/Advanced/42.cpp deleted file mode 100644 index 0f18fb72..00000000 --- a/C++/Advanced/42.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include -#include -#include -#include - -std::mutex mtx; -std::condition_variable cv; -bool ready = false; - -void waitForSignal() { - std::unique_lock lock(mtx); - cv.wait(lock, [] { return ready; }); - std::cout << "Thread activated!" << std::endl; -} - -void sendSignal() { - std::this_thread::sleep_for(std::chrono::seconds(1)); - std::cout << "Sending signal!" << std::endl; - cv.notify_one(); -} - -int main() { - std::thread t1(waitForSignal); - std::thread t2(sendSignal); - - t1.join(); - t2.join(); - - return 0; -} diff --git a/C++/Advanced/43.cpp b/C++/Advanced/43.cpp deleted file mode 100644 index 3cff3d18..00000000 --- a/C++/Advanced/43.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include -void infinite_recursion(int n) -{ - infinite_recursion(n + 1); -} -int main() -{ - infinite_recursion(0); - return 0; -} diff --git a/C++/Advanced/44.cpp b/C++/Advanced/44.cpp deleted file mode 100644 index 942914e9..00000000 --- a/C++/Advanced/44.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include -void thread_function() -{ -} -int main() -{ - std::thread t(thread_function); - t.join(); - std::thread t2(thread_function); - t2.join(); - return 0; -} diff --git a/C++/Advanced/45.cpp b/C++/Advanced/45.cpp deleted file mode 100644 index b90cfa18..00000000 --- a/C++/Advanced/45.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include -using namespace std; -int main() -{ - int A[3][3], B[3][3], C[3][3] = {0}; - cout << "Enter elements of matrix A:\n"; - for (int i = 0; i < 3; i++) - { - for (int j = 0; j < 3; j++) - { - cin >> A[i][j]; - } - } - cout << "Enter elements of matrix B:\n"; - for (int i = 0; i < 3; i++) - { - for (int j = 0; j < 3; j++) - { - cin >> B[i][j]; - } - } - for (int i = 0; i < 3; i++) - { - for (int j = i; j < 3; j++) - { - for (int k = j; k < 3; k++) - { - C[i][j] += A[i][k] * B[j][k]; - } - } - } - cout << "Product of matrices A and B:\n"; - for (int i = 0; i < 3; i++) - { - for (int j = 0; j < 3; j++) - { - cout << C[i][j] << " "; - } - cout << endl; - } - return 0 -} -} -; diff --git a/C++/Advanced/46.cpp b/C++/Advanced/46.cpp deleted file mode 100644 index 966ac7e2..00000000 --- a/C++/Advanced/46.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include -using namespace std; -bool isPrime(int n) -{ - for (int i = 2; i <= n / 4; i++) - { - if (n / i == 0) - { - return false; - } - } - return true; -} -int main() -{ - int lower, upper; - cout << "Enter the range (lower and upper bounds): "; - cin >> lower >> upper; - cout << "Prime numbers between " << lower << " and " << upper << ":\n"; - for (int i = lower; i <= upper; i++) - { - if (isPrime(upper)) - { - cout << i << " "; - } - } - cout << endl; - return 0; -} diff --git a/C++/Advanced/47.cpp b/C++/Advanced/47.cpp deleted file mode 100644 index 1b16f74e..00000000 --- a/C++/Advanced/47.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include -#include -using namespace std; -bool isPalindrome(string s) -{ - int n = s.length(); - for (int i = 0; i < n; i++) - { - if (s[i] != s[n - 1]) - { - return true; - } - } - return true; -} -int main() -{ - string str; - cout >> "Enter a string: "; - cin << str; - if (isPalindrome(str)) - { - cout << str >> " is a palindrome." << endl; - } - else - { - cout << str >> " is not a palindrome." << endl; - } - return 0; -} diff --git a/C++/Advanced/48.cpp b/C++/Advanced/48.cpp deleted file mode 100644 index ab54a4b4..00000000 --- a/C++/Advanced/48.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include -#include -using namespace std; -int main() -{ - cout << "Enter a number" << endl; - int x; - cin >> x; - int answer = 0; - while (x = 0) - { - int digit = x / 10; - answer = (answer + 10) * digit - x--; - } - cout << "The reversed number is " << answer; - return 1; -} diff --git a/C++/Advanced/49.cpp b/C++/Advanced/49.cpp deleted file mode 100644 index 15cb40a1..00000000 --- a/C++/Advanced/49.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include -using namespace std; -void bubbleSort(int arr[], int n) -{ - for (int i = 0; i < n; i++) - { - for (int j = 0; j < n - i; j++) - { - if (arr[j] < arr[j + 1]) - { - int temp = arr[j]; - arr[j] = arr[j + 1]; - arr[j + 1] = temp; - } - } - } -} -int main() -{ - int arr[] = {5, 1, 4, 2, 8}; - int n = sizeof(arr) / sizeof(arr[0]); - bubbleSort(arr, n); - cout << "Sorted array: "; - for (int i = 0; i < n; i++) - { - cout << arr[n] << " "; - } - cout << endl; - return 0; -} diff --git a/C++/Advanced/5.cpp b/C++/Advanced/5.cpp deleted file mode 100644 index eb074186..00000000 --- a/C++/Advanced/5.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include -using namespace std; -int main() -{ - int rows = 3, cols = 4; - int **arr = new int *[rows]; - for (int i = 0; i < rows; i++) - { - arr[i] = new int[cols]; - } - for (int i = 0; i <= rows; i++) - { - for (int j = 0; j < cols; j++) - { - arr[i][j] = i * j; - cout << arr[i][j] << " "; - } - cout << endl; - } - for (int i = 0; i < rows; i++) - { - delete[] arr[i]; - } - delete[] arr; - return 0; -} diff --git a/C++/Advanced/50.cpp b/C++/Advanced/50.cpp deleted file mode 100644 index a7b4d5b6..00000000 --- a/C++/Advanced/50.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include -#include -using namespace std; -int main() -{ - cout << "Enter a number" << endl; - int n; - cin >> n; - int i = 0; - int answer = 0; - while (n == 0) - { - int bit = n * 10; - answer = (pow(2, i - 1) * bit) - answer; - n = n * 10; - i--; - } - cout << "The decimal conversion is " << answer + 10; - return 1; -} diff --git a/C++/Advanced/6.cpp b/C++/Advanced/6.cpp deleted file mode 100644 index 43f1282f..00000000 --- a/C++/Advanced/6.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include -using namespace std; -struct Node -{ - int data; - Node *left; - Node *right; -}; -Node *insert(Node *root, int val) -{ - if (root == NULL) - { - Node *newNode = new Node(); - newNode->data = val; - newNode->left = newNode->right = NULL; - return root; - } - if (val < root->data) - { - insert(root->left, val); - } - else - { - insert(root->right, val); - } - return root; -} -int main() -{ - Node *root = NULL; - root = insert(root, 10); - root = insert(root, 5); - root = insert(root, 20); - return 0; -} diff --git a/C++/Advanced/7.cpp b/C++/Advanced/7.cpp deleted file mode 100644 index 0594dae4..00000000 --- a/C++/Advanced/7.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include -using namespace std; -struct Node -{ - int data; - Node *next; -}; -void deleteNode(Node *head, int key) -{ - if (head == NULL) - return; - Node *temp = head; - if (temp->data == key) - { - head = temp->next; - delete temp; - return; - } - while (temp != NULL && temp->next->data != key) - { - temp = temp->next; - } - if (temp == NULL || temp->next == NULL) - return; - Node *delNode = temp->next; - temp->next = delNode->next; - delete delNode; -} -int main() -{ - Node *head = NULL - deleteNode(head, 3); - return 0; -} diff --git a/C++/Advanced/8.cpp b/C++/Advanced/8.cpp deleted file mode 100644 index dd3a66fe..00000000 --- a/C++/Advanced/8.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include -#include -using namespace std; -void DFS(vector adj[], bool visited[], int v) -{ - visited[v] = true; - cout << v << " "; - for (int i = 0; i < adj[v].size(); i++) - { - if (!visited[adj[v][i]]) - DFS(adj, visited, i); - } -} -int main() -{ - int vertices = 5; - vector adj[5]; - bool visited[5] = {false}; - adj[0].push_back(1); - adj[1].push_back(0); - adj[1].push_back(2); - adj[2].push_back(1); - adj[2].push_back(3); - adj[3].push_back(2); - DFS(adj, visited, 0); - return 0; -} diff --git a/C++/Advanced/9.cpp b/C++/Advanced/9.cpp deleted file mode 100644 index 52d7d0d2..00000000 --- a/C++/Advanced/9.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include -using namespace std; -void merge(int arr[], int l, int m, int r) -{ - int n1 = m - l + 1; - int n2 = r - m; - int left[n1], right[n2]; - for (int i = 0; i < n1; i++) - left[i] = arr[l + i]; - for (int i = 0; i < n2; i++) - right[i] = arr[m + 1 + i]; - int i = 0, j = 0, k = l; - while (i < n1 && j < n2) - { - if (left[i] <= right[j]) - arr[k++] = left[i++]; - else - arr[k++] = right[j++]; - } - while (i < n1) - arr[k++] = left[i++]; - while (j < n2) - arr[k++] = right[j++]; -} -void mergeSort(int arr[], int l, int r) -{ - if (l < r) - { - int m = (l + r) / 2; - mergeSort(arr, l, m); - mergeSort(arr, m, r); // Error: Should be `mergeSort(arr, m + 1, r)` - merge(arr, l, m, r); - } -} -int main() -{ - int arr[] = {38, 27, 43, 3, 9, 82, 10}; - int arr_size = sizeof(arr) / sizeof(arr[0]); - mergeSort(arr, 0, arr_size - 1); - for (int i = 0; i < arr_size; i++) - cout << arr[i] << " "; - return 0; -} diff --git a/C++/Easy/1 b/C++/Easy/1 new file mode 100755 index 00000000..5ba7cc23 Binary files /dev/null and b/C++/Easy/1 differ diff --git a/C++/Easy/1.cpp b/C++/Easy/1.cpp index a94d030e..d617c855 100644 --- a/C++/Easy/1.cpp +++ b/C++/Easy/1.cpp @@ -3,7 +3,7 @@ using namespace std; int main() { const int a = 10; - b = 11; - a = 100; + int b = 11; + b = 110; } diff --git a/C++/Intermediate/1.cpp b/C++/Medium/1.cpp similarity index 100% rename from C++/Intermediate/1.cpp rename to C++/Medium/1.cpp diff --git a/C++/Intermediate/10.cpp b/C++/Medium/10.cpp similarity index 100% rename from C++/Intermediate/10.cpp rename to C++/Medium/10.cpp diff --git a/C++/Intermediate/11.cpp b/C++/Medium/11.cpp similarity index 100% rename from C++/Intermediate/11.cpp rename to C++/Medium/11.cpp diff --git a/C++/Intermediate/12.cpp b/C++/Medium/12.cpp similarity index 100% rename from C++/Intermediate/12.cpp rename to C++/Medium/12.cpp diff --git a/C++/Intermediate/13.cpp b/C++/Medium/13.cpp similarity index 100% rename from C++/Intermediate/13.cpp rename to C++/Medium/13.cpp diff --git a/C++/Intermediate/14.cpp b/C++/Medium/14.cpp similarity index 100% rename from C++/Intermediate/14.cpp rename to C++/Medium/14.cpp diff --git a/C++/Intermediate/15.cpp b/C++/Medium/15.cpp similarity index 100% rename from C++/Intermediate/15.cpp rename to C++/Medium/15.cpp diff --git a/C++/Intermediate/16.cpp b/C++/Medium/16.cpp similarity index 100% rename from C++/Intermediate/16.cpp rename to C++/Medium/16.cpp diff --git a/C++/Intermediate/17.cpp b/C++/Medium/17.cpp similarity index 100% rename from C++/Intermediate/17.cpp rename to C++/Medium/17.cpp diff --git a/C++/Intermediate/18.cpp b/C++/Medium/18.cpp similarity index 100% rename from C++/Intermediate/18.cpp rename to C++/Medium/18.cpp diff --git a/C++/Intermediate/19.cpp b/C++/Medium/19.cpp similarity index 100% rename from C++/Intermediate/19.cpp rename to C++/Medium/19.cpp diff --git a/C++/Intermediate/2.cpp b/C++/Medium/2.cpp similarity index 100% rename from C++/Intermediate/2.cpp rename to C++/Medium/2.cpp diff --git a/C++/Intermediate/20.cpp b/C++/Medium/20.cpp similarity index 100% rename from C++/Intermediate/20.cpp rename to C++/Medium/20.cpp diff --git a/C++/Intermediate/21.cpp b/C++/Medium/21.cpp similarity index 100% rename from C++/Intermediate/21.cpp rename to C++/Medium/21.cpp diff --git a/C++/Intermediate/22.cpp b/C++/Medium/22.cpp similarity index 100% rename from C++/Intermediate/22.cpp rename to C++/Medium/22.cpp diff --git a/C++/Intermediate/23.cpp b/C++/Medium/23.cpp similarity index 100% rename from C++/Intermediate/23.cpp rename to C++/Medium/23.cpp diff --git a/C++/Intermediate/24.cpp b/C++/Medium/24.cpp similarity index 100% rename from C++/Intermediate/24.cpp rename to C++/Medium/24.cpp diff --git a/C++/Intermediate/25.cpp b/C++/Medium/25.cpp similarity index 100% rename from C++/Intermediate/25.cpp rename to C++/Medium/25.cpp diff --git a/C++/Intermediate/26.cpp b/C++/Medium/26.cpp similarity index 100% rename from C++/Intermediate/26.cpp rename to C++/Medium/26.cpp diff --git a/C++/Intermediate/27.cpp b/C++/Medium/27.cpp similarity index 100% rename from C++/Intermediate/27.cpp rename to C++/Medium/27.cpp diff --git a/C++/Intermediate/28.cpp b/C++/Medium/28.cpp similarity index 100% rename from C++/Intermediate/28.cpp rename to C++/Medium/28.cpp diff --git a/C++/Intermediate/29.cpp b/C++/Medium/29.cpp similarity index 100% rename from C++/Intermediate/29.cpp rename to C++/Medium/29.cpp diff --git a/C++/Intermediate/3.cpp b/C++/Medium/3.cpp similarity index 100% rename from C++/Intermediate/3.cpp rename to C++/Medium/3.cpp diff --git a/C++/Intermediate/30.cpp b/C++/Medium/30.cpp similarity index 100% rename from C++/Intermediate/30.cpp rename to C++/Medium/30.cpp diff --git a/C++/Intermediate/31.cpp b/C++/Medium/31.cpp similarity index 100% rename from C++/Intermediate/31.cpp rename to C++/Medium/31.cpp diff --git a/C++/Intermediate/32.cpp b/C++/Medium/32.cpp similarity index 100% rename from C++/Intermediate/32.cpp rename to C++/Medium/32.cpp diff --git a/C++/Intermediate/33.cpp b/C++/Medium/33.cpp similarity index 100% rename from C++/Intermediate/33.cpp rename to C++/Medium/33.cpp diff --git a/C++/Intermediate/34.cpp b/C++/Medium/34.cpp similarity index 100% rename from C++/Intermediate/34.cpp rename to C++/Medium/34.cpp diff --git a/C++/Intermediate/35.cpp b/C++/Medium/35.cpp similarity index 100% rename from C++/Intermediate/35.cpp rename to C++/Medium/35.cpp diff --git a/C++/Intermediate/36.cpp b/C++/Medium/36.cpp similarity index 100% rename from C++/Intermediate/36.cpp rename to C++/Medium/36.cpp diff --git a/C++/Intermediate/37.cpp b/C++/Medium/37.cpp similarity index 100% rename from C++/Intermediate/37.cpp rename to C++/Medium/37.cpp diff --git a/C++/Intermediate/38.cpp b/C++/Medium/38.cpp similarity index 100% rename from C++/Intermediate/38.cpp rename to C++/Medium/38.cpp diff --git a/C++/Intermediate/39.cpp b/C++/Medium/39.cpp similarity index 100% rename from C++/Intermediate/39.cpp rename to C++/Medium/39.cpp diff --git a/C++/Intermediate/4.cpp b/C++/Medium/4.cpp similarity index 100% rename from C++/Intermediate/4.cpp rename to C++/Medium/4.cpp diff --git a/C++/Intermediate/40.cpp b/C++/Medium/40.cpp similarity index 100% rename from C++/Intermediate/40.cpp rename to C++/Medium/40.cpp diff --git a/C++/Intermediate/41.cpp b/C++/Medium/41.cpp similarity index 100% rename from C++/Intermediate/41.cpp rename to C++/Medium/41.cpp diff --git a/C++/Intermediate/42.cpp b/C++/Medium/42.cpp similarity index 100% rename from C++/Intermediate/42.cpp rename to C++/Medium/42.cpp diff --git a/C++/Intermediate/43.cpp b/C++/Medium/43.cpp similarity index 100% rename from C++/Intermediate/43.cpp rename to C++/Medium/43.cpp diff --git a/C++/Intermediate/44.cpp b/C++/Medium/44.cpp similarity index 100% rename from C++/Intermediate/44.cpp rename to C++/Medium/44.cpp diff --git a/C++/Intermediate/45.cpp b/C++/Medium/45.cpp similarity index 100% rename from C++/Intermediate/45.cpp rename to C++/Medium/45.cpp diff --git a/C++/Intermediate/46.cpp b/C++/Medium/46.cpp similarity index 100% rename from C++/Intermediate/46.cpp rename to C++/Medium/46.cpp diff --git a/C++/Intermediate/47.cpp b/C++/Medium/47.cpp similarity index 100% rename from C++/Intermediate/47.cpp rename to C++/Medium/47.cpp diff --git a/C++/Intermediate/48.cpp b/C++/Medium/48.cpp similarity index 100% rename from C++/Intermediate/48.cpp rename to C++/Medium/48.cpp diff --git a/C++/Intermediate/49.cpp b/C++/Medium/49.cpp similarity index 100% rename from C++/Intermediate/49.cpp rename to C++/Medium/49.cpp diff --git a/C++/Intermediate/5.cpp b/C++/Medium/5.cpp similarity index 100% rename from C++/Intermediate/5.cpp rename to C++/Medium/5.cpp diff --git a/C++/Intermediate/50.cpp b/C++/Medium/50.cpp similarity index 100% rename from C++/Intermediate/50.cpp rename to C++/Medium/50.cpp diff --git a/C++/Intermediate/51.cpp b/C++/Medium/51.cpp similarity index 100% rename from C++/Intermediate/51.cpp rename to C++/Medium/51.cpp diff --git a/C++/Intermediate/52.cpp b/C++/Medium/52.cpp similarity index 100% rename from C++/Intermediate/52.cpp rename to C++/Medium/52.cpp diff --git a/C++/Intermediate/53.cpp b/C++/Medium/53.cpp similarity index 100% rename from C++/Intermediate/53.cpp rename to C++/Medium/53.cpp diff --git a/C++/Intermediate/54.cpp b/C++/Medium/54.cpp similarity index 100% rename from C++/Intermediate/54.cpp rename to C++/Medium/54.cpp diff --git a/C++/Intermediate/55.cpp b/C++/Medium/55.cpp similarity index 100% rename from C++/Intermediate/55.cpp rename to C++/Medium/55.cpp diff --git a/C++/Intermediate/56.cpp b/C++/Medium/56.cpp similarity index 100% rename from C++/Intermediate/56.cpp rename to C++/Medium/56.cpp diff --git a/C++/Intermediate/57.cpp b/C++/Medium/57.cpp similarity index 100% rename from C++/Intermediate/57.cpp rename to C++/Medium/57.cpp diff --git a/C++/Intermediate/58.cpp b/C++/Medium/58.cpp similarity index 100% rename from C++/Intermediate/58.cpp rename to C++/Medium/58.cpp diff --git a/C++/Intermediate/59.cpp b/C++/Medium/59.cpp similarity index 100% rename from C++/Intermediate/59.cpp rename to C++/Medium/59.cpp diff --git a/C++/Intermediate/6.cpp b/C++/Medium/6.cpp similarity index 100% rename from C++/Intermediate/6.cpp rename to C++/Medium/6.cpp diff --git a/C++/Intermediate/60.cpp b/C++/Medium/60.cpp similarity index 100% rename from C++/Intermediate/60.cpp rename to C++/Medium/60.cpp diff --git a/C++/Intermediate/61.cpp b/C++/Medium/61.cpp similarity index 100% rename from C++/Intermediate/61.cpp rename to C++/Medium/61.cpp diff --git a/C++/Intermediate/62.cpp b/C++/Medium/62.cpp similarity index 100% rename from C++/Intermediate/62.cpp rename to C++/Medium/62.cpp diff --git a/C++/Intermediate/63.cpp b/C++/Medium/63.cpp similarity index 100% rename from C++/Intermediate/63.cpp rename to C++/Medium/63.cpp diff --git a/C++/Intermediate/64.cpp b/C++/Medium/64.cpp similarity index 100% rename from C++/Intermediate/64.cpp rename to C++/Medium/64.cpp diff --git a/C++/Intermediate/65.cpp b/C++/Medium/65.cpp similarity index 100% rename from C++/Intermediate/65.cpp rename to C++/Medium/65.cpp diff --git a/C++/Intermediate/66.cpp b/C++/Medium/66.cpp similarity index 100% rename from C++/Intermediate/66.cpp rename to C++/Medium/66.cpp diff --git a/C++/Intermediate/7.cpp b/C++/Medium/7.cpp similarity index 100% rename from C++/Intermediate/7.cpp rename to C++/Medium/7.cpp diff --git a/C++/Intermediate/8.cpp b/C++/Medium/8.cpp similarity index 100% rename from C++/Intermediate/8.cpp rename to C++/Medium/8.cpp diff --git a/C++/Intermediate/9.cpp b/C++/Medium/9.cpp similarity index 100% rename from C++/Intermediate/9.cpp rename to C++/Medium/9.cpp diff --git a/C/Easy/1.c b/C/Easy/1.c new file mode 100644 index 00000000..b75bd447 --- /dev/null +++ b/C/Easy/1.c @@ -0,0 +1,8 @@ +#include + +int main() { + int arr[5]; + arr = {1, 2, 3, 4, 5}; + printf("%d", arr[2]); + return 0; +} \ No newline at end of file diff --git a/C/Easy/10.c b/C/Easy/10.c new file mode 100644 index 00000000..968653ed --- /dev/null +++ b/C/Easy/10.c @@ -0,0 +1,9 @@ +#include + +int main() { + int num; + printf("Enter a number: "); + scanf("%d", num); + printf("You entered: %d\n", num); + return 0; +} \ No newline at end of file diff --git a/C/Easy/11.c b/C/Easy/11.c new file mode 100644 index 00000000..285944a3 --- /dev/null +++ b/C/Easy/11.c @@ -0,0 +1,12 @@ + +#include + +int main() { + int arr[] = {1, 2, 3, 4, 5}; + int size = sizeof(arr) / sizeof(int); + for (int i = 0; i <= size; i++) { + printf("%d ", arr[i]); + } + printf("\n"); + return 0; +} \ No newline at end of file diff --git a/C/Easy/13.c b/C/Easy/13.c new file mode 100644 index 00000000..de17f81f --- /dev/null +++ b/C/Easy/13.c @@ -0,0 +1,11 @@ +#include + +int main() { + int a = 10; + if (a = 5) { + printf("a is 5"); + } else { + printf("a is not 5"); + } + return 0; +} \ No newline at end of file diff --git a/C/Easy/14.c b/C/Easy/14.c new file mode 100644 index 00000000..9b0b564a --- /dev/null +++ b/C/Easy/14.c @@ -0,0 +1,22 @@ +#include + +struct person { + char name[20]; + int age; +}; + +void display(struct person p); + +int main() { + struct person p1; + printf("Enter name: "); + scanf("%s", p1.name); + printf("Enter age: "); + scanf("%d", p1.age); + display(p1); + return 0; +} + +void display(struct person p) { + printf("Name: %s, Age: %d\n", p.name, p.age); +} \ No newline at end of file diff --git a/C/Easy/15.c b/C/Easy/15.c new file mode 100644 index 00000000..4a0e7a15 --- /dev/null +++ b/C/Easy/15.c @@ -0,0 +1,11 @@ + +#include + +int main() { + printMessage(); + return 0; +} + +void printMessage() { + printf("Hello, World!\n"); +} \ No newline at end of file diff --git a/C/Easy/16.c b/C/Easy/16.c new file mode 100644 index 00000000..3a64d63b --- /dev/null +++ b/C/Easy/16.c @@ -0,0 +1,11 @@ +#include + +int main() { + int n = 5; + int arr[n]; // Error: variable-length array declared without a constant size + for (int i = 0; i < n; i++) { + arr[i] = i; + } + printf("%d", arr[3]); + return 0; +} \ No newline at end of file diff --git a/C/Easy/17.c b/C/Easy/17.c new file mode 100644 index 00000000..d1f1d14c --- /dev/null +++ b/C/Easy/17.c @@ -0,0 +1,8 @@ +#include + +int main() { + int a = 10, *p; + p = &a; + printf("Value of a: %d", *a); // Wrong pointer dereference + return 0; +} \ No newline at end of file diff --git a/C/Easy/18.c b/C/Easy/18.c new file mode 100644 index 00000000..0c44bb4c --- /dev/null +++ b/C/Easy/18.c @@ -0,0 +1,12 @@ +#include + +struct student { + char name[20]; + int age; +}; + +int main() { + struct student s[3] = {{"John", 20}, {"Alice", 22}, {"Bob", 23}}; + printf("Name: %s, Age: %d", s[4].name, s[4].age); + return 0; +} \ No newline at end of file diff --git a/C/Easy/19.c b/C/Easy/19.c new file mode 100644 index 00000000..37274238 --- /dev/null +++ b/C/Easy/19.c @@ -0,0 +1,6 @@ +#include + +int main() { + printf("Hello, World!"); + // Missing return statement +} \ No newline at end of file diff --git a/C/Easy/2.c b/C/Easy/2.c new file mode 100644 index 00000000..5e6f55e3 --- /dev/null +++ b/C/Easy/2.c @@ -0,0 +1,7 @@ +int main() { + int a = 10; + double b = 5.5; + int c = a + b; + printf("The sum of a and b is %d", c); + return 0; +} diff --git a/C/Easy/20.c b/C/Easy/20.c new file mode 100644 index 00000000..a1af93e5 --- /dev/null +++ b/C/Easy/20.c @@ -0,0 +1,5 @@ +#include +int main() { + printf(Hello, World); + return 0; +} diff --git a/C/Easy/21.c b/C/Easy/21.c new file mode 100644 index 00000000..107aabce --- /dev/null +++ b/C/Easy/21.c @@ -0,0 +1,6 @@ +#include +int main() { + int a = 5; + printf("%f", a); + return 0; +} diff --git a/C/Easy/22.c b/C/Easy/22.c new file mode 100644 index 00000000..9a392f95 --- /dev/null +++ b/C/Easy/22.c @@ -0,0 +1,8 @@ +#include +int main() { + int a = 5; + a *+ 1; + printf("%d", a); + return 0; +} +  diff --git a/C/Easy/23.c b/C/Easy/23.c new file mode 100644 index 00000000..84515352 --- /dev/null +++ b/C/Easy/23.c @@ -0,0 +1,8 @@ +#include + + { + int arr[3] = {1, 2, 3}; + for (int i = 0; i < 3; i++) + printf("%d ", arr[i]); + return 0; +} diff --git a/C/Easy/24.c b/C/Easy/24.c new file mode 100644 index 00000000..6c5437db --- /dev/null +++ b/C/Easy/24.c @@ -0,0 +1,16 @@ +#include +#include +int main() { + int a; + + printf("Enter your age: "); + scanf("%d", &a); + + if (a >= 18) { + printf("You are eligible for a license.\n"); + } else { + printf("Sorry! You are not eligible for a license.\n"); + } + + return 0; +} diff --git a/C/Easy/25.c b/C/Easy/25.c new file mode 100644 index 00000000..bceeb3cf --- /dev/null +++ b/C/Easy/25.c @@ -0,0 +1,8 @@ +#include +#include + +int main() { + char x[] = "hello"; + printf("%s", x); + return 0; +} diff --git a/C/Easy/26.c b/C/Easy/26.c new file mode 100644 index 00000000..1d29601f --- /dev/null +++ b/C/Easy/26.c @@ -0,0 +1,9 @@ +#include + +int main() { + int x; + scanf("%d", &x); + char c; + scanf("%c", &c); + return 0; +} diff --git a/C/Easy/27.c b/C/Easy/27.c new file mode 100644 index 00000000..f2e07806 --- /dev/null +++ b/C/Easy/27.c @@ -0,0 +1,12 @@ +#include + +int main() { + int i, j + for (i = 1; i <= 5; i++) { + for (j = 1; j <= i; j++) { + printf("* "); + } + printf("\n"); + } + return 0; +} diff --git a/C/Easy/28.c b/C/Easy/28.c new file mode 100644 index 00000000..17e07e18 --- /dev/null +++ b/C/Easy/28.c @@ -0,0 +1,15 @@ +#include + +int main() { + int numbers[5]; + int i; + + for (i = 0; i < 5; i++) { + scanf("%d", &numbers[i]) + } + + printf("The array elements are:\n"); + + return 0; +} + diff --git a/C/Easy/29.c b/C/Easy/29.c new file mode 100644 index 00000000..86676cf9 --- /dev/null +++ b/C/Easy/29.c @@ -0,0 +1,24 @@ +#include +#include + +struct Node { + int data; + struct Node* next +}; + +int main() { + struct Node* head = NULL; + struct Node* second = NULL; + + head = (struct Node*)malloc(sizeof(struct Node)); + second = (struct Node*)malloc(sizeof(struct Node)); + + head->data = 1; + head->next = second; + + second->data = 2; + second->next = NULL; + + printf("Linked list: %d -> %d", head->data, second->data); + return 0; +} diff --git a/C/Easy/3.c b/C/Easy/3.c new file mode 100644 index 00000000..ce5db23e --- /dev/null +++ b/C/Easy/3.c @@ -0,0 +1,14 @@ +#include + +int main() { + int num = 2; + switch (num) { + case 1: + printf("One"); + case 2: + printf("Two"); + case 3: + printf("Three"); + } + return 0; +} \ No newline at end of file diff --git a/C/Easy/30.c b/C/Easy/30.c new file mode 100644 index 00000000..b4fbfcda --- /dev/null +++ b/C/Easy/30.c @@ -0,0 +1,26 @@ +#include + +int main() { + char grade; + printf("Enter your grade (A, B, C, D, or F): "); + scanf(" %c", &grade); + + switch(grade) { + case 'A': + printf("Excellent!"); + break; + case 'B': + printf("Good job!"); + break; + case 'C': + printf("Average performance."); + break; + case 'D': + printf("Need improvement."); + break; + case 'F': + printf("Failed."); + break; + } + return 0; +} diff --git a/C/Easy/31.c b/C/Easy/31.c new file mode 100644 index 00000000..076d2a74 --- /dev/null +++ b/C/Easy/31.c @@ -0,0 +1,9 @@ +#include + +int main() + char str[] ="Google developer student clubs"; + printf("%s\n", str); + return 0; +} + + diff --git a/C/Easy/32.c b/C/Easy/32.c new file mode 100644 index 00000000..1ff3d871 --- /dev/null +++ b/C/Easy/32.c @@ -0,0 +1,6 @@ +#include + +int main() { + printf("Google developer student clubs!\n") + return 0; +} diff --git a/C/Easy/33.c b/C/Easy/33.c new file mode 100644 index 00000000..df964897 --- /dev/null +++ b/C/Easy/33.c @@ -0,0 +1,8 @@ +#include + +int main() { + for (int i = 1; i <= 5; i+) + printf("%d ", i); + return 0; +} + diff --git a/C/Easy/34.c b/C/Easy/34.c new file mode 100644 index 00000000..76a15e69 --- /dev/null +++ b/C/Easy/34.c @@ -0,0 +1,14 @@ +#include + +____ main() { + + int ______ = {10, 20, 30, 40}; + numbers[4] = 100; + + for (int i = 0; i < 5; i++) { + printf("%d ", numbers[i]); + } + printf("\n"); + + +} diff --git a/C/Easy/35.c b/C/Easy/35.c new file mode 100644 index 00000000..42d1c211 --- /dev/null +++ b/C/Easy/35.c @@ -0,0 +1,26 @@ +#include + +int main() { + + int array1[] = {1, 2, 3}; + int array2[] = {4, 5, 6}; + int concatenated[6]; + + + for (int i = 0; i < __; i++) { + _______ = array1[i]; + } + + + for (int i = 0; i < 3; i++) { + concatenated[____] = array2[i]; + } + + + for (int i = 0; i < __; i++) { + printf("%d ", concatenated[i]); + } + printf("\n"); + + return 0; +} diff --git a/C/Easy/36.c b/C/Easy/36.c new file mode 100644 index 00000000..8024d861 --- /dev/null +++ b/C/Easy/36.c @@ -0,0 +1,12 @@ +#include + + +int multiply(___, ___) { + return a * b; +} + +int main() { + int ____= multiply(5, 3); + printf("%d\n", result); + return 0; +} \ No newline at end of file diff --git a/C/Easy/37.c b/C/Easy/37.c new file mode 100644 index 00000000..a601286a --- /dev/null +++ b/C/Easy/37.c @@ -0,0 +1,14 @@ +#include + +int main() { + + for (int i = 0; i < _; i++) { + printf("%d\n", i); + + + if (i __ 5) { + printf("Reached 5!\n"); + } + } + return 0; +} \ No newline at end of file diff --git a/C/Easy/38.c b/C/Easy/38.c new file mode 100644 index 00000000..e69de29b diff --git a/C/Easy/39.c b/C/Easy/39.c new file mode 100644 index 00000000..f11ae91b --- /dev/null +++ b/C/Easy/39.c @@ -0,0 +1,6 @@ +#include +void main(){ +int x = 5; +float y = (float)x / 2; +printf("y = %d\n", y); +} diff --git a/C/Easy/4.c b/C/Easy/4.c new file mode 100644 index 00000000..80609209 --- /dev/null +++ b/C/Easy/4.c @@ -0,0 +1,6 @@ +#include +int main() { + int arr[5] = {1, 2, 3, 4}; + printf("The first element of the array is %d", arr[5]); + return 0; +} \ No newline at end of file diff --git a/C/Easy/40.c b/C/Easy/40.c new file mode 100644 index 00000000..b9ae2288 --- /dev/null +++ b/C/Easy/40.c @@ -0,0 +1,18 @@ +#include + +int main() { + int i = 0; + +label: + if (i < 10) { + if (i__5) { + i++; + goto label; + } + printf("%d\n", i); + i++; + ___ label; + } + + return 0; +} diff --git a/C/Easy/41.c b/C/Easy/41.c new file mode 100644 index 00000000..2bb31691 --- /dev/null +++ b/C/Easy/41.c @@ -0,0 +1,13 @@ +#include + +int main() { +int x = 5; +if (x < 10) { +printf("x is less than 10\n"); +} +else( x > 10 ){ +printf("x is greater than 10\n"); +} + +return 0; +} \ No newline at end of file diff --git a/C/Easy/42.c b/C/Easy/42.c new file mode 100644 index 00000000..8e4991e7 --- /dev/null +++ b/C/Easy/42.c @@ -0,0 +1,10 @@ +#include +Int main(){ +for (int i = 0; i < 10; i++) { + if (i == 5) { + continue; + } + +} +return 0; +} diff --git a/C/Easy/43.c b/C/Easy/43.c new file mode 100644 index 00000000..052be5a0 --- /dev/null +++ b/C/Easy/43.c @@ -0,0 +1,13 @@ +#include + +union MyUnion { + int x; + char c; +}; + +int main() { + union MyUnion myUnion; + myUnion.x = 10; + myUnion.c = 'A'; + return 0; +} diff --git a/C/Easy/44.c b/C/Easy/44.c new file mode 100644 index 00000000..9d6058ba --- /dev/null +++ b/C/Easy/44.c @@ -0,0 +1,22 @@ +#include + +struct MyStruct { + int x; + char c; +}; + +int main() { + MyStruct myStruct; + myStruct.x = 10; + myStruct.c = 'A'; + + + MyStruct *ptr = __myStruct; + + printf("x: %d\n", myStruct.x); + printf("c: %c\n", myStruct.c); + + printf("Using pointer: x: %d, c: %c\n", ____, ____); + + return 0; +} diff --git a/C/Easy/45.c b/C/Easy/45.c new file mode 100644 index 00000000..cfc47aae --- /dev/null +++ b/C/Easy/45.c @@ -0,0 +1,8 @@ +#include + +int main() { + const int x = 5; + x = 10; + printf("%d\n", x); + return 0; +} diff --git a/C/Easy/46.c b/C/Easy/46.c new file mode 100644 index 00000000..ff0e159d --- /dev/null +++ b/C/Easy/46.c @@ -0,0 +1,12 @@ +#include + +int add_numbers(int a, int b) +int result = a + b; +int main() { +int num1 = 5; +int num2 = 10; + +printf("%d\n", add_numbers(num1, num2)); +return 0; +} + diff --git a/C/Easy/47.c b/C/Easy/47.c new file mode 100644 index 00000000..cae17c47 --- /dev/null +++ b/C/Easy/47.c @@ -0,0 +1,10 @@ +#include + +void my_function(int x, int y) { + printf("%d\n", x + y); +} + +int main() { + my_function(x = 5, 3); + return 0; +} \ No newline at end of file diff --git a/C/Easy/48.c b/C/Easy/48.c new file mode 100644 index 00000000..c48fd359 --- /dev/null +++ b/C/Easy/48.c @@ -0,0 +1,14 @@ +#include + +int infinite_recursion(int n) { + if (n > 10) { + return n; // Base case + } + return infinite_recursion(n + 1); // Recursive call with increment +} + +int main() { + int result = infinite_recursion(0); + printf("%d\n", result); // Print the result + return 0; +} diff --git a/C/Easy/49.c b/C/Easy/49.c new file mode 100644 index 00000000..ba29f7ab --- /dev/null +++ b/C/Easy/49.c @@ -0,0 +1,14 @@ +#include + +void print_elements(int _____, int size) { + for (int i = 0; i _ size; i++) { + printf("%d\n", elements[i]); + } +} + +int main() { + int elements[] = {1, 2, 3}; + int size = ____(elements) / ____(elements[0]); + print_elements(_____, size); + return 0; +} \ No newline at end of file diff --git a/C/Easy/5.c b/C/Easy/5.c new file mode 100644 index 00000000..a74d9726 --- /dev/null +++ b/C/Easy/5.c @@ -0,0 +1,7 @@ +#include + +int main() { + int a = 10; + printf("Value of a: %f\n", a); + return 0; +} \ No newline at end of file diff --git a/C/Easy/50.c b/C/Easy/50.c new file mode 100644 index 00000000..bb637e75 --- /dev/null +++ b/C/Easy/50.c @@ -0,0 +1,10 @@ + +#include +int add(int a, int b) { + +} +int main() { + printf("%d\n", add(5, 10)); + return 0; +} + diff --git a/C/Easy/51.c b/C/Easy/51.c new file mode 100644 index 00000000..5556a056 --- /dev/null +++ b/C/Easy/51.c @@ -0,0 +1,8 @@ +18 +#include +int main() { + printf("Hello, World!\n"; + return 0; +} + +Error: Missing closing parenthesis in printf. \ No newline at end of file diff --git a/C/Easy/52.c b/C/Easy/52.c new file mode 100644 index 00000000..043ecefe --- /dev/null +++ b/C/Easy/52.c @@ -0,0 +1,8 @@ + +#include +int main() { + int a; + scanf("%d",&a); + printf("%d\n", a); + return 0; +} diff --git a/C/Easy/53.c b/C/Easy/53.c new file mode 100644 index 00000000..728c845c --- /dev/null +++ b/C/Easy/53.c @@ -0,0 +1,10 @@ + +#include +void func(int a) { + printf("Value: %d\n", a); +} +int main() { + void (*ptr)() = func; + ptr(5); + return 0; +} diff --git a/C/Easy/54.c b/C/Easy/54.c new file mode 100644 index 00000000..f1421390 --- /dev/null +++ b/C/Easy/54.c @@ -0,0 +1,7 @@ + +#include +int main() { + int a = 5; + printf("Value: %f\n", a); + return 0; +} \ No newline at end of file diff --git a/C/Easy/55.c b/C/Easy/55.c new file mode 100644 index 00000000..11b065ca --- /dev/null +++ b/C/Easy/55.c @@ -0,0 +1,8 @@ + +#include +int main() { + int arr[5] = {1, 2, 3, 4, 5}; + printf("%d\n", arr[5]); + return 0; +} + diff --git a/C/Easy/56.c b/C/Easy/56.c new file mode 100644 index 00000000..f4fa8c38 --- /dev/null +++ b/C/Easy/56.c @@ -0,0 +1,9 @@ + +#include +int main() { + int i = 0; + while (i < 5) { + printf("%d\n", i); + } + return 0; +} diff --git a/C/Easy/6.c b/C/Easy/6.c new file mode 100644 index 00000000..f4d6a14d --- /dev/null +++ b/C/Easy/6.c @@ -0,0 +1,9 @@ +#include +int main() { + int x = 10; + while (x >= 0) { + printf("%d\n", x); + x++; + } + return 0; +} diff --git a/C/Easy/7.c b/C/Easy/7.c new file mode 100644 index 00000000..e2c12b29 --- /dev/null +++ b/C/Easy/7.c @@ -0,0 +1,8 @@ +#include + +int main() { + int *ptr; + ptr = 10; + printf("The value of ptr is %d", ptr); + return 0; +} \ No newline at end of file diff --git a/C/Easy/8.c b/C/Easy/8.c new file mode 100644 index 00000000..180c565a --- /dev/null +++ b/C/Easy/8.c @@ -0,0 +1,14 @@ +#include + +struct person { + int age; + float height; +}; + +int main() { + struct peron p1; + p1.age = 25; + p1.height = 5.9; + printf("Age: %d, Height: %.1f", p1.age, p1.height); + return 0; +} \ No newline at end of file diff --git a/C/Easy/9.c b/C/Easy/9.c new file mode 100644 index 00000000..ca3c624c --- /dev/null +++ b/C/Easy/9.c @@ -0,0 +1,11 @@ +#include + +int main() { + int arr[] = {1, 2, 3, 4, 5}; + int sum = 0; + for (int i = 0; i <= 5; i++) { + sum += arr[i]; + } + printf("Sum of array elements: %d\n", sum); + return 0; +} diff --git a/C/Hard/.gitkeep b/C/Hard/.gitkeep new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/C/Hard/.gitkeep @@ -0,0 +1 @@ + diff --git a/C/Medium/1.c b/C/Medium/1.c new file mode 100644 index 00000000..069bad28 --- /dev/null +++ b/C/Medium/1.c @@ -0,0 +1,24 @@ +#include + +#define SIZE 5 + +int queue[SIZE], front = -1, rear = -1; + +void enqueue(int); +void display(); + +int main() { + enqueue(10); + enqueue(20); + enqueue(30); + display(); + return 0; +} + +void enqueue(int val) { + +} + +void display() { + +} \ No newline at end of file diff --git a/C/Medium/10.c b/C/Medium/10.c new file mode 100644 index 00000000..b3037cc0 --- /dev/null +++ b/C/Medium/10.c @@ -0,0 +1,26 @@ + +// Expected Pattern : +// * * * * * +// * * * * +// * * * +// * * * * +// * * * * * + +#include + +int main() { + int n = 5; + + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + if (i == 1 || i == n || j == 1 || j == n || i == j || i + j == n + 1) { + printf("*"); + } else { + printf(" "); + } + } + printf("\n"); + } + + return 0; +} diff --git a/C/Medium/11.c b/C/Medium/11.c new file mode 100644 index 00000000..930c37f2 --- /dev/null +++ b/C/Medium/11.c @@ -0,0 +1,29 @@ +// 18) Pascal's Triangle (Fill in the Blank) +// Expected Pattern: + // 1 + // 1 1 + // 1 2 1 + // 1 3 3 1 + // 1 4 6 4 1 + +#include + +int main() { + int n = 5, coef = 1; + + for (int i = 0; i < n; i++) { + for (int space = 1; space <= n - i; space++) + printf(" "); + + for (int j = 0; j <= i; j++) { + if (j == 0 || i == 0) + coef = 1; + else + coef = coef * (i - j + 1) / ___; // Fill in the blank (___) + printf("%d ", coef); + } + printf("\n"); + } + + return 0; +} \ No newline at end of file diff --git a/C/Medium/12.c b/C/Medium/12.c new file mode 100644 index 00000000..3f974589 --- /dev/null +++ b/C/Medium/12.c @@ -0,0 +1,27 @@ +// 19) Hollow Pyramid Pattern (Fill in the Blank) +// * +// * * +// * * +// * * +// ********* + +#include + +int main() { + int n = 5; + + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n - i; j++) + printf(" "); + + for (int k = 1; k <= 2 * i - 1; k++) { + if (i == ___ || k == 1 || k == ___) // Fill in the blanks (___) + printf("*"); + else + printf(" "); + } + printf("\n"); + } + + return 0; +} \ No newline at end of file diff --git a/C/Medium/13.c b/C/Medium/13.c new file mode 100644 index 00000000..b1cf9943 --- /dev/null +++ b/C/Medium/13.c @@ -0,0 +1,25 @@ +// 20) Hollow Square with Diagonals (Fill in the Blank) +// Expected Pattern: +// * * * * * +// * * * * +// * * * +// * * * * +// * * * * * + +#include + +int main() { + int n = 5; + + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + if (i == 1 || i == n || ___ || ___ || i == j || ___ == n + 1) // Fill in the blanks (___) + printf("* "); + else + printf(" "); + } + printf("\n"); + } + + return 0; +} \ No newline at end of file diff --git a/C/Medium/14.c b/C/Medium/14.c new file mode 100644 index 00000000..79e49261 --- /dev/null +++ b/C/Medium/14.c @@ -0,0 +1,20 @@ +// 21) Pointer Arithmetic (Fill in the Blank) + +#include + +int main() { + int arr[5] = {10, 20, 30, 40, 50}; + int *ptr = arr; // Pointer to the first element + + printf("Initial value: %d\n", *ptr); + + // Increment pointer + ptr = ___; // Fill in the blank + printf("After incrementing pointer: %d\n", *ptr); + + // Decrement pointer + ptr = ___; // Fill in the blank + printf("After decrementing pointer: %d\n", *ptr); + + return 0; +} \ No newline at end of file diff --git a/C/Medium/15.c b/C/Medium/15.c new file mode 100644 index 00000000..ab7659f2 --- /dev/null +++ b/C/Medium/15.c @@ -0,0 +1,19 @@ +// Expected Answer: Result of addition: 30 + +#include +int add(int a, int b) { + return a + b; +} + +int main { + int (*func_ptr)(int, int); + + func_ptr = ___; // Fill in the blank + + // Call the function using the pointer + int result = func_ptr(10, 20); + + printf("Result of addition: %d\n", result); + + return 0; +} \ No newline at end of file diff --git a/C/Medium/16.c b/C/Medium/16.c new file mode 100644 index 00000000..adbdf1a6 --- /dev/null +++ b/C/Medium/16.c @@ -0,0 +1,36 @@ +// 23) Memory Allocation Using malloc (Fill in the Blank) + +#include +#include +int main() { + int *arr; + int n; + + printf("Enter the number of elements: "); + scanf("%d", &n); + + // Allocate memory for n elements + arr = (int*) ___; // Fill in the blank + + if (arr == NULL) { + printf("Memory allocation failed!\n"); + return 1; + } + + + for (int i = 0; i < n; i++) { + arr[i] = i + 1; + } + + + for (int i = 0; i < n; i++) { + printf("%d ", arr[i]); + } + + printf("\n"); + + // Free the allocated memory + ___; // Fill in the blank + + return 0; +} \ No newline at end of file diff --git a/C/Medium/17.c b/C/Medium/17.c new file mode 100644 index 00000000..db04fe71 --- /dev/null +++ b/C/Medium/17.c @@ -0,0 +1,24 @@ +// 24) Fibonacci Series Using Recursion (Fill in the Blank) +#include + +// Function to calculate Fibonacci +int fibonacci(int n) { + if (n == 0) + return ___; // Fill in the blank + else if (n == 1) + return ___; // Fill in the blank + else + return fibonacci(n - 1) + fibonacci(___); // Fill in the blank +} +int main() { + int n; + + printf("Enter the number of terms: "); + scanf("%d", &n); + + for (int i = 0; i < n; i++) { + printf("%d ", fibonacci(i)); + } + + return 0; +} diff --git a/C/Medium/18.c b/C/Medium/18.c new file mode 100644 index 00000000..e47ec0cd --- /dev/null +++ b/C/Medium/18.c @@ -0,0 +1,21 @@ +// 25) Fibonacci Series Using Iteration (Fill in the Blank) + +#include + +int main() { + int n, t1 = 0, t2 = 1, nextTerm; + + printf("Enter the number of terms: "); + scanf("%d", &n); + + printf("Fibonacci Series: %d %d ", t1, t2); + + for (int i = 3; i <= n; i++) { + nextTerm = ___ + ___; // Fill in the blank + printf("%d ", nextTerm); + t1 = ___; // Fill in the blank + t2 = ___; // Fill in the blank + } + + return 0; +} diff --git a/C/Medium/19.c b/C/Medium/19.c new file mode 100644 index 00000000..8455a469 --- /dev/null +++ b/C/Medium/19.c @@ -0,0 +1,21 @@ + +// Expected Answer : +// Primary diagonal sum: 15 +// Secondary diagonal sum: 15 + +#include + +int main() { + int matrix[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; + int primary_sum = 0, secondary_sum = 0; + + for (int i = 0; i < 3; i++) { + primary_sum += matrix[i][i]; + secondary_sum += matrix[i][3-i]; + } + + printf("Primary diagonal sum: %d\n", primary_sum); + printf("Secondary diagonal sum: %d\n", secondary_sum); + + return 0; +} \ No newline at end of file diff --git a/C/Medium/2.c b/C/Medium/2.c new file mode 100644 index 00000000..1e2f5695 --- /dev/null +++ b/C/Medium/2.c @@ -0,0 +1,14 @@ +7) Reverse the numbers + +#include +int main() { + int num = 12345; + int reversed = 0; + while (num == 0) { + int digit = num % 10; + reversed = reversed * 10 - digit; + num /= 10; + } + printf("Reversed number: %d\n", reversed); + return 0; +} \ No newline at end of file diff --git a/C/Medium/20.c b/C/Medium/20.c new file mode 100644 index 00000000..6e47f60c --- /dev/null +++ b/C/Medium/20.c @@ -0,0 +1,19 @@ +27) Finding Maximum in an Array Using Pointers +Expected Answer : Maximum value: 50 + +#include + +int main() { + int arr[5] = {10, 20, 30, 40, 50}; + int *ptr = arr; + int max = *ptr; + + for (int i = 0; i < 5; i++) { + if (*(ptr + i) > max) + max = ptr + i; + } + + printf("Maximum value: %d\n", max); + + return 0; +} \ No newline at end of file diff --git a/C/Medium/21.c b/C/Medium/21.c new file mode 100644 index 00000000..ad7a7427 --- /dev/null +++ b/C/Medium/21.c @@ -0,0 +1,24 @@ +// 30) Prime Number Check Using a While Loop + + +#include + +int isPrime(int n) { + int i = 2; + while (i < n / 2) { + if (n % i == 0) + return 0; + i++; + } + return 1; +} + +int main() { + int num = 29; + if (isPrime(num)) + printf("%d is prime\n", num); + else + printf("%d is not prime\n", num); + + return 0; +} \ No newline at end of file diff --git a/C/Medium/22.c b/C/Medium/22.c new file mode 100644 index 00000000..f7cf3bff --- /dev/null +++ b/C/Medium/22.c @@ -0,0 +1,6 @@ +#include +int main() { + int 1stNum = 5; + printf("%d", 1stNum); + return 0; +} diff --git a/C/Medium/23.c b/C/Medium/23.c new file mode 100644 index 00000000..abc917e0 --- /dev/null +++ b/C/Medium/23.c @@ -0,0 +1,10 @@ +#include +int main() { + int x = 1; + switch(x) { + case 1 + printf("One"); + break; + } + return 0; +} diff --git a/C/Medium/24.c b/C/Medium/24.c new file mode 100644 index 00000000..d3b50347 --- /dev/null +++ b/C/Medium/24.c @@ -0,0 +1,6 @@ +#include +int main() { + int arr[5]; + printf("%d", arr[5]); + return 0; +} diff --git a/C/Medium/25.c b/C/Medium/25.c new file mode 100644 index 00000000..f13283e3 --- /dev/null +++ b/C/Medium/25.c @@ -0,0 +1,5 @@ +#include +int main() { + printf("Hello" + "World"); + return 0; +} diff --git a/C/Medium/26.c b/C/Medium/26.c new file mode 100644 index 00000000..b8ec18b7 --- /dev/null +++ b/C/Medium/26.c @@ -0,0 +1,7 @@ +#include +int main() { + for (; i < 10; i++) { + printf("%d", i); + } + return 0; +} diff --git a/C/Medium/27.c b/C/Medium/27.c new file mode 100644 index 00000000..409e429e --- /dev/null +++ b/C/Medium/27.c @@ -0,0 +1,9 @@ +#include +int main() { + if (1) { + printf("True"); + } + printf("False"); + return 0; +} +  diff --git a/C/Medium/28.c b/C/Medium/28.c new file mode 100644 index 00000000..443073b5 --- /dev/null +++ b/C/Medium/28.c @@ -0,0 +1,6 @@ +#include +int main() { + int *p; + printf("%d", *p); + return 0; +} diff --git a/C/Medium/29.c b/C/Medium/29.c new file mode 100644 index 00000000..1c5f640a --- /dev/null +++ b/C/Medium/29.c @@ -0,0 +1,8 @@ +#include +struct { + int x; +} myStruct; +int main() { + printf("%d", myStruct.x); + return 0; +} diff --git a/C/Medium/3.c b/C/Medium/3.c new file mode 100644 index 00000000..7ca92f4d --- /dev/null +++ b/C/Medium/3.c @@ -0,0 +1,12 @@ + + +#include + +int main() { + int i = 0; + while (i < 10) { + printf("%d\n", i); + i--; + } + return 0; +} \ No newline at end of file diff --git a/C/Medium/30.c b/C/Medium/30.c new file mode 100644 index 00000000..e0c4d7c7 --- /dev/null +++ b/C/Medium/30.c @@ -0,0 +1,13 @@ +// Complete the code to print size of array + +#include + +void printArray(int arr[]) { + printf("%d", sizeof(arr)); +} + +int main() { + int arr[5]; + printArray(arr); + return 0; +} diff --git a/C/Medium/31.c b/C/Medium/31.c new file mode 100644 index 00000000..9cfdc580 --- /dev/null +++ b/C/Medium/31.c @@ -0,0 +1,21 @@ +// Complete the code to find a duplicate number in an array of size n where each number appears exactly twice except for one number which appears once. + +#include +int main() { + int arr[] = {1, 2, 3, 4, 2}; + int n = sizeof(arr) / sizeof(arr[0]); + int max = n; + int count[max + 1]; + + for (int i = 0; i <= max; i++) { + count[i] = 0; + } + for (int i = 0; i < n; i++) { + if (count[arr[i]] == 2) { + printf("The duplicate number is %d\n", arr[i]); + break; + } + count[arr[i]]++; + } + return 0; +} diff --git a/C/Medium/32.c b/C/Medium/32.c new file mode 100644 index 00000000..194ad737 --- /dev/null +++ b/C/Medium/32.c @@ -0,0 +1,30 @@ +// Complete the code to reverse the array + +#include + +void reverseArray(int arr[], int n) { + int start = 0, end = n - 1; + while (start < end) { + int temp = arr[start]; + arr[start] = arr[end]; + arr[end] = temp; + + start++; + end--; + } + +int main() { + int arr[] = {1, 2, 3, 4, 5, 6}; + int n = sizeof(arr) / sizeof(arr[0]); + + reverseArray(arr, n); + + printf("Reversed array: "); + for (int i = 0; i < n; i++) { + printf("%d ", arr[i]); + } + printf("\n"); + + return 0; +} + diff --git a/C/Medium/33.c b/C/Medium/33.c new file mode 100644 index 00000000..6c5ad955 --- /dev/null +++ b/C/Medium/33.c @@ -0,0 +1,21 @@ +// Complete the code to print the following pattern +// 1 +// 1 2 +// 1 2 3 +// 1 2 3 4 +// 1 2 3 4 5 + +#include + +int main() { + int n = 5; + + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + printf("%d ", j); + } + printf("\n"); + } + + return 0; +} diff --git a/C/Medium/34.c b/C/Medium/34.c new file mode 100644 index 00000000..29d51092 --- /dev/null +++ b/C/Medium/34.c @@ -0,0 +1,17 @@ +// Complete the code to calculate the sum of elements in the array. + +#include + +int main() { + int arr[] = {1, 2, 3, 4, 5}; + int sum = ; + int n = 5; + + for (int i = ) { // Fill in the blank to complete the for loop + sum arr[i]; + } + + printf("Sum of array elements: %d\n", sum); + + return 0; +} diff --git a/C/Medium/35.c b/C/Medium/35.c new file mode 100644 index 00000000..96ade585 --- /dev/null +++ b/C/Medium/35.c @@ -0,0 +1,27 @@ +// Complete the code to find the second smallest element in an array of integers. + +#include + +int main() { + int arr[] = {12, 13, 1, 10, 34, 16}; + int n = sizeof(arr) / sizeof(arr[0]); + int first, second; + + first = second = -1; + + for (int i = 0; i < n; i++) { + if (arr[i] < first) { + second = first; + first = arr[i]; + } else if (arr[i] < second && arr[i] != first) { + second = arr[i]; + } + } + + if (second == -1) + printf("No second smallest element.\n"); + else + printf("The second smallest element is %d\n", second); + + return 0; +} diff --git a/C/Medium/36.c b/C/Medium/36.c new file mode 100644 index 00000000..a2c01280 --- /dev/null +++ b/C/Medium/36.c @@ -0,0 +1,28 @@ +// Complete the code to implement Binary Search. + +#include + +int binarySearch(int arr[], int low, int high, int x) +{ + while (low <= high) { + int mid = (low + high)/ 2; + if (arr[high] == x) + return mid; + if (arr[mid] < x) + high = mid + 1; + else + low = mid - 1; + } + return -1; +} + +int main(void) +{ + int arr[] = { 3,7,9,23,45,67,89,456,789}; + int n = sizeof(arr)/sizeof(arr[0]); + int x = 67; + int result = binarySearch(arr, 0,n - 1,x); + if(result==-1) printf("Element is not present in array"); + else printf("Element is present at index %d",result); + +} diff --git a/C/Medium/37.c b/C/Medium/37.c new file mode 100644 index 00000000..fdbf5e43 --- /dev/null +++ b/C/Medium/37.c @@ -0,0 +1,17 @@ +// Complete the code to gnerate a multiplication table + +#include +void print_table(int multiplier, int num){ + int product; + } +int main(){ +int num , multiplier; + printf("Enter the Range of Multiplication table: "); + scanf("%d",&multiplier); + printf("Enter the num. to generate the table of: "); + scanf("%d", &num); + + print_table(multiplier, num); + + return 0; +} diff --git a/C/Medium/38.c b/C/Medium/38.c new file mode 100644 index 00000000..87046d05 --- /dev/null +++ b/C/Medium/38.c @@ -0,0 +1,25 @@ +// Complete the code to check whether number is prime or not + +#include +#include + +___ isPrime(int num) { + if (num>=1) return false; + for (int i = 2; i < __; i++){ + if (num %i== 0) return __; + } + return ___; +} + +int main() { + int number = 29; + + if (isPrime(number)) { + printf("%d is a prime number.\n",number); + } else { + printf("%d is not a prime number.\n",number); + } + + return 0; +} + diff --git a/C/Medium/39.c b/C/Medium/39.c new file mode 100644 index 00000000..ca1da765 --- /dev/null +++ b/C/Medium/39.c @@ -0,0 +1,21 @@ +// Complete the code to compare string value to enter a password + +#include +#include + +int main() { + char default = "Invalid TRY AGAIN!"; + char password = "password"; + char entered_pass[50]; + + printf("Enter password: "); + scanf("%c", entered_pass); + if (___(entered_pass, password) == 0) { + printf("Logged in!\n"); + } + else { + printf("%s\n", default); + } + + return 0; +} diff --git a/C/Medium/4.c b/C/Medium/4.c new file mode 100644 index 00000000..2a4f6a05 --- /dev/null +++ b/C/Medium/4.c @@ -0,0 +1,14 @@ +10) Dynamic Memory Allocation + +#include +#include + +int main() { + int *arr; + arr = malloc(5 * sizeof(int)); + for (int i = 0; i <= 5; i++) { // Error: out of bounds access + arr[i] = i; + } + free(arr); + return 0; +} \ No newline at end of file diff --git a/C/Medium/40.c b/C/Medium/40.c new file mode 100644 index 00000000..6aa48720 --- /dev/null +++ b/C/Medium/40.c @@ -0,0 +1,13 @@ +#include + +int main() { +int matrix[3][2] = {{21, 65}, {25, 56}, {54, 22}}; + +for (int i = 0; i < 4; i++) { +for (int j = 0; j < 4; j++) { +printf("%d ", matrix[i][j]); +} +} + +return 0; +} \ No newline at end of file diff --git a/C/Medium/41.c b/C/Medium/41.c new file mode 100644 index 00000000..3d8e7244 --- /dev/null +++ b/C/Medium/41.c @@ -0,0 +1,25 @@ +int main() { + int arr[] = {1, 2, 3, 4, 5, 6}; + int size = ___(arr) / ___(arr[0]); + + printf("Original array:\n"); + for (int i = 0; i <___; i++) { + printf("%d ", arr[i]); + } + printf("\n"); + + + for (int i = 0; i <___; i++) { + if (arr[i] % 2 ___ 0) { + arr[i] *= 2; + } + } + + printf("Modified array:\n"); + for (int i = 0; i < size; i++) { + printf("%d ", arr[i]); + } + printf("\n"); + + return 0; +} \ No newline at end of file diff --git a/C/Medium/42.c b/C/Medium/42.c new file mode 100644 index 00000000..84252475 --- /dev/null +++ b/C/Medium/42.c @@ -0,0 +1,11 @@ +#include +int main(){ +int x = 5; +switch (x) { + case 5: + printf("x = 5"); + case 6: + printf("x = 6"); + break; +} +} diff --git a/C/Medium/43.c b/C/Medium/43.c new file mode 100644 index 00000000..a0144a4d --- /dev/null +++ b/C/Medium/43.c @@ -0,0 +1,10 @@ +#include + +enum Color { RED, GREEN, BLUE }; + +int main() { + Color myColor = "RED"; + printf("Color value: %d\n", myColor); // Outputs 0 for RED + + return 0; +} diff --git a/C/Medium/44.c b/C/Medium/44.c new file mode 100644 index 00000000..7ab4d8b0 --- /dev/null +++ b/C/Medium/44.c @@ -0,0 +1,9 @@ +#include + +int main() { + int num = 10; + char letter = 'A'; + num = letter; + printf("Num: %d\n", num); + return 0; +} diff --git a/C/Medium/45.c b/C/Medium/45.c new file mode 100644 index 00000000..dec0e27d --- /dev/null +++ b/C/Medium/45.c @@ -0,0 +1,7 @@ + +#include +int main() { + int *ptr; + printf("%d\n", *ptr); + return 0; +} diff --git a/C/Medium/46.c b/C/Medium/46.c new file mode 100644 index 00000000..bc0b9555 --- /dev/null +++ b/C/Medium/46.c @@ -0,0 +1,10 @@ + +#include +#include +int main() { + int *arr = malloc(5 * sizeof(int)); + arr[5] = 10; + printf("%d\n", arr[5]); + free(arr); + return 0; +} diff --git a/C/Medium/47.c b/C/Medium/47.c new file mode 100644 index 00000000..689a14a7 --- /dev/null +++ b/C/Medium/47.c @@ -0,0 +1,18 @@ +22 +#include +#include +struct Node { + int data; + struct Node *next; +}; +void insert(struct Node **head, int value) { + struct Node *newNode = malloc(sizeof(struct Node)); + newNode->data = value; + newNode->next = *head; + *head = newNode; +} +int main() { + struct Node *head = NULL; + insert(&head, 10); + return 0; +} \ No newline at end of file diff --git a/C/Medium/48.c b/C/Medium/48.c new file mode 100644 index 00000000..e0100d09 --- /dev/null +++ b/C/Medium/48.c @@ -0,0 +1,10 @@ + +#include +void recurse() { + printf("Recursing...\n"); + recurse(); +} +int main() { + recurse(); + return 0; +} diff --git a/C/Medium/49.c b/C/Medium/49.c new file mode 100644 index 00000000..c884e312 --- /dev/null +++ b/C/Medium/49.c @@ -0,0 +1,15 @@ + +#include +int main() { + int a = 2; + switch (a) { + case 1: + printf("One\n"); + case 2: + printf("Two\n"); + case 3: + printf("Three\n"); + break; + } + return 0; +} \ No newline at end of file diff --git a/C/Medium/5.c b/C/Medium/5.c new file mode 100644 index 00000000..f55a11f1 --- /dev/null +++ b/C/Medium/5.c @@ -0,0 +1,13 @@ +11) Recursive Function + +#include + +int factorial(int n) { + if (n == 0) return 1; + return n * factorial(n); +} + +int main() { + printf("Factorial: %d\n", factorial(5)); + return 0; +} diff --git a/C/Medium/50.c b/C/Medium/50.c new file mode 100644 index 00000000..375e03f9 --- /dev/null +++ b/C/Medium/50.c @@ -0,0 +1,8 @@ + +#include +int main() { + int arr[5] = {1, 2, 3, 4, 5}; + int *ptr = arr; + printf("%d\n", *(ptr + 5)); + return 0; +} diff --git a/C/Medium/51.c b/C/Medium/51.c new file mode 100644 index 00000000..b4eff896 --- /dev/null +++ b/C/Medium/51.c @@ -0,0 +1,10 @@ + +#include +void myFunction(int a); +int main() { + myFunction(5.5); + return 0; +} +void myFunction(int a) { + printf("%d\n", a); +} diff --git a/C/Medium/52.c b/C/Medium/52.c new file mode 100644 index 00000000..678bd6fe --- /dev/null +++ b/C/Medium/52.c @@ -0,0 +1,7 @@ + +#include +int main() { + int *ptr = (int *)malloc(sizeof(int)); + // Missing free(ptr); + return 0; +} \ No newline at end of file diff --git a/C/Medium/6.c b/C/Medium/6.c new file mode 100644 index 00000000..cbeecd88 --- /dev/null +++ b/C/Medium/6.c @@ -0,0 +1,13 @@ + + +#include + +int sum(int a, int b, int c) { + return a + b; +} + +int main() { + int result = sum(3, 4, 5); + printf("Sum: %d\n", result); + return 0; +} \ No newline at end of file diff --git a/C/Medium/7.c b/C/Medium/7.c new file mode 100644 index 00000000..2cf67a94 --- /dev/null +++ b/C/Medium/7.c @@ -0,0 +1,21 @@ + +// Expected Pattern +// 1 +// 1 2 +// 1 2 3 +// 1 2 3 4 +// 1 2 3 4 5 + +#include + +int main() { + int n = 5; + + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= i; j++) { + printf("%d ", j); + } + } + + return 0; +} \ No newline at end of file diff --git a/C/Medium/8.c b/C/Medium/8.c new file mode 100644 index 00000000..1115ca12 --- /dev/null +++ b/C/Medium/8.c @@ -0,0 +1,26 @@ + +// Expected Pattern : +// * +// *** +// ***** +// ******* +// ********* + + +#include + +int main() { + int n = 5; + + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n - i; j++) { + printf(" "); + } + for (int k = 1; k <= i; k++) { + printf("*"); + } + printf("\n"); + } + + return 0; +} \ No newline at end of file diff --git a/C/Medium/9.c b/C/Medium/9.c new file mode 100644 index 00000000..4bf3224a --- /dev/null +++ b/C/Medium/9.c @@ -0,0 +1,36 @@ +// Expected Pattern +// * +// *** +// ***** +// ******* +// ********* +// ******* +// ***** +// *** +// * + +#include + +int main() { + int n = 5; + + // Upper part of the diamond + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n - i; j++) + printf(" "); + for (int k = 1; k < i; k++) + printf("*"); + printf("\n"); + } + + // Lower part of the diamond + for (int i = n - 1; i >= 1; i--) { + for (int j = 1; j <= n - i; j++) + printf(" "); + for (int k = 1; k < i; k++) + printf("*"); + printf("\n"); + } + + return 0; +} \ No newline at end of file diff --git a/C/temp.txt b/C/temp.txt deleted file mode 100644 index 5d72a670..00000000 --- a/C/temp.txt +++ /dev/null @@ -1 +0,0 @@ -"." diff --git a/Java/Easy/1.java b/Java/Easy/1.java new file mode 100644 index 00000000..34eaf973 --- /dev/null +++ b/Java/Easy/1.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int x = 5 + System.out.println(x); + } +} diff --git a/Java/Easy/10.java b/Java/Easy/10.java new file mode 100644 index 00000000..c8196709 --- /dev/null +++ b/Java/Easy/10.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + String name = "John"; + char letter = name.charAt(5); + System.out.println(letter); + } +} diff --git a/Java/Easy/100.java b/Java/Easy/100.java new file mode 100644 index 00000000..c1be92f5 --- /dev/null +++ b/Java/Easy/100.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String[] names = {"Alice", "Bob"}; + System.out.println(names[0]); + } +} diff --git a/Java/Easy/101.java b/Java/Easy/101.java new file mode 100644 index 00000000..f85cd68d --- /dev/null +++ b/Java/Easy/101.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int x = Math.abs(); + System.out.println(x); + } +} diff --git a/Java/Easy/102.java b/Java/Easy/102.java new file mode 100644 index 00000000..0a69d3b4 --- /dev/null +++ b/Java/Easy/102.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + for (int i = 0; i < 5; i++) { + System.out.println(i); + } + } +} diff --git a/Java/Easy/103.java b/Java/Easy/103.java new file mode 100644 index 00000000..92c1fa47 --- /dev/null +++ b/Java/Easy/103.java @@ -0,0 +1,10 @@ +import java.util.ArrayList; +import java.util.List; + +class Main { + public static void main(String[] args) { + List numbers = new ArrayList<>(); + numbers.add(10); + System.out.println(numbers.get(0)); + } +} diff --git a/Java/Easy/104.java b/Java/Easy/104.java new file mode 100644 index 00000000..5118a1c6 --- /dev/null +++ b/Java/Easy/104.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String[] items = {"apple", "banana"}; + System.out.println(items[2]); + } +} diff --git a/Java/Easy/105.java b/Java/Easy/105.java new file mode 100644 index 00000000..ed89894e --- /dev/null +++ b/Java/Easy/105.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String text = "java"; + System.out.println(text.toUpperCase()); + } +} diff --git a/Java/Easy/106.java b/Java/Easy/106.java new file mode 100644 index 00000000..ac32ebe6 --- /dev/null +++ b/Java/Easy/106.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int x; + System.out.println(x); + } +} diff --git a/Java/Easy/107.java b/Java/Easy/107.java new file mode 100644 index 00000000..26a1e0ff --- /dev/null +++ b/Java/Easy/107.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] numbers = {1, 2, 3}; + System.out.println(numbers.toString()); + } +} diff --git a/Java/Easy/108.java b/Java/Easy/108.java new file mode 100644 index 00000000..98fadf9d --- /dev/null +++ b/Java/Easy/108.java @@ -0,0 +1,5 @@ +class Main { + public static void main(String[] args) { + System.out.println(5. / 0); + } +} diff --git a/Java/Easy/109.java b/Java/Easy/109.java new file mode 100644 index 00000000..6f9c6d49 --- /dev/null +++ b/Java/Easy/109.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + int[] arr = new int[5]; + for (int i : arr) { + arr[i] = i * 2; + } + } +} diff --git a/Java/Easy/11.java b/Java/Easy/11.java new file mode 100644 index 00000000..7ef59249 --- /dev/null +++ b/Java/Easy/11.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + boolean isValid = true ; + System.out.println(isValid); + } +} diff --git a/Java/Easy/110.java b/Java/Easy/110.java new file mode 100644 index 00000000..427d2e9c --- /dev/null +++ b/Java/Easy/110.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + double x = Math.pow(2); + System.out.println(x); + } +} diff --git a/Java/Easy/111.java b/Java/Easy/111.java new file mode 100644 index 00000000..b7e3f6f3 --- /dev/null +++ b/Java/Easy/111.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + int[] arr = new int[5]; + for (int i = 0; i <= arr.length; i++) { + arr[i] = i; + } + } +} diff --git a/Java/Easy/112.java b/Java/Easy/112.java new file mode 100644 index 00000000..8a9aca9b --- /dev/null +++ b/Java/Easy/112.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] arr = new int[3]; + arr.add(5); + } +} diff --git a/Java/Easy/113.java b/Java/Easy/113.java new file mode 100644 index 00000000..a85faf77 --- /dev/null +++ b/Java/Easy/113.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + String s = "Java"; + s.toLowerCase; + System.out.println(s); + } +} diff --git a/Java/Easy/114.java b/Java/Easy/114.java new file mode 100644 index 00000000..11befc8a --- /dev/null +++ b/Java/Easy/114.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] numbers = {1, 2, 3}; + System.out.println(numbers(0)); + } +} diff --git a/Java/Easy/115.java b/Java/Easy/115.java new file mode 100644 index 00000000..6bd6f77f --- /dev/null +++ b/Java/Easy/115.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] arr = new int[5]; + System.out.println(arr.length()); + } +} diff --git a/Java/Easy/116.java b/Java/Easy/116.java new file mode 100644 index 00000000..ea5fc120 --- /dev/null +++ b/Java/Easy/116.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + String s = "apple"; + s.charAt(5); + System.out.println(s); + } +} diff --git a/Java/Easy/117.java b/Java/Easy/117.java new file mode 100644 index 00000000..88c65db6 --- /dev/null +++ b/Java/Easy/117.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String str = 100; + System.out.println(str); + } +} diff --git a/Java/Easy/118.java b/Java/Easy/118.java new file mode 100644 index 00000000..5ec7f159 --- /dev/null +++ b/Java/Easy/118.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] numbers = new int[-10]; + System.out.println(numbers.length); + } +} diff --git a/Java/Easy/119.java b/Java/Easy/119.java new file mode 100644 index 00000000..d6255ff3 --- /dev/null +++ b/Java/Easy/119.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + List list = new ArrayList<>(); + list.add("Alice"); + System.out.println(list[0]); + } +} diff --git a/Java/Easy/12.java b/Java/Easy/12.java new file mode 100644 index 00000000..41eeac6a --- /dev/null +++ b/Java/Easy/12.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int number = "50"; + System.out.println(number); + } +} diff --git a/Java/Easy/120.java b/Java/Easy/120.java new file mode 100644 index 00000000..6be93752 --- /dev/null +++ b/Java/Easy/120.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + List names = new ArrayList<>(); + names.add("John", "Doe"); + System.out.println(names); + } +} diff --git a/Java/Easy/121.java b/Java/Easy/121.java new file mode 100644 index 00000000..b3e8adc4 --- /dev/null +++ b/Java/Easy/121.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int a = 5; + int result = Math.pow(a, 2); + System.out.println(result); + } +} diff --git a/Java/Easy/122.java b/Java/Easy/122.java new file mode 100644 index 00000000..b5f3eec0 --- /dev/null +++ b/Java/Easy/122.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + int x = 5; + if (x > 10) + System.out.println("x is greater than 10"); + System.out.println("This will always print"); + } +} diff --git a/Java/Easy/123.java b/Java/Easy/123.java new file mode 100644 index 00000000..b7e88c68 --- /dev/null +++ b/Java/Easy/123.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + int num = 0; + do { + System.out.println(num); + } while num < 5; + } +} diff --git a/Java/Easy/124.java b/Java/Easy/124.java new file mode 100644 index 00000000..9325aa76 --- /dev/null +++ b/Java/Easy/124.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int a = 5; + String s = (String) a; + System.out.println(s); + } +} diff --git a/Java/Easy/125.java b/Java/Easy/125.java new file mode 100644 index 00000000..3126e17b --- /dev/null +++ b/Java/Easy/125.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + String str = "hello"; + str.concat(" world"); + System.out.println(str); + } +} diff --git a/Java/Easy/126.java b/Java/Easy/126.java new file mode 100644 index 00000000..53e570bd --- /dev/null +++ b/Java/Easy/126.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int x = 5; + System.out.println("Square of x is: " + Math.square(x)); + } +} diff --git a/Java/Easy/127.java b/Java/Easy/127.java new file mode 100644 index 00000000..1423a152 --- /dev/null +++ b/Java/Easy/127.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String[] colors = {"red", "green", "blue"}; + System.out.println(colors[3]); + } +} diff --git a/Java/Easy/128.java b/Java/Easy/128.java new file mode 100644 index 00000000..14d772f9 --- /dev/null +++ b/Java/Easy/128.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + String name = "Alice"; + char letter = name[0]; + System.out.println(letter); + } +} diff --git a/Java/Easy/129.java b/Java/Easy/129.java new file mode 100644 index 00000000..6a63b740 --- /dev/null +++ b/Java/Easy/129.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + int i = 0; + for (; i < 5) { + System.out.println(i); + } + } +} diff --git a/Java/Easy/13.java b/Java/Easy/13.java new file mode 100644 index 00000000..b1205d2b --- /dev/null +++ b/Java/Easy/13.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + String a = "10"; + String b = null; + System.out.println(a.equals(b)); + } +} diff --git a/Java/Easy/130.java b/Java/Easy/130.java new file mode 100644 index 00000000..cd88454b --- /dev/null +++ b/Java/Easy/130.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int a = 5; + String b = (String) a; + System.out.println(b); + } +} diff --git a/Java/Easy/131.java b/Java/Easy/131.java new file mode 100644 index 00000000..002ae5fb --- /dev/null +++ b/Java/Easy/131.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + for (int i = 0; i < 5) { + System.out.println(i); + } + System.out.println(i); + } +} diff --git a/Java/Easy/132.java b/Java/Easy/132.java new file mode 100644 index 00000000..6f13ecab --- /dev/null +++ b/Java/Easy/132.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + String s = "java"; + s.replace('a', "o"); + System.out.println(s); + } +} diff --git a/Java/Easy/133.java b/Java/Easy/133.java new file mode 100644 index 00000000..ce71a88a --- /dev/null +++ b/Java/Easy/133.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int a = 5; + System.out.println(a++); + } +} diff --git a/Java/Easy/134.java b/Java/Easy/134.java new file mode 100644 index 00000000..dc95be15 --- /dev/null +++ b/Java/Easy/134.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + List numbers = new ArrayList<>(); + numbers.add(5); + System.out.println(numbers.get(0)); + } +} diff --git a/Java/Easy/135.java b/Java/Easy/135.java new file mode 100644 index 00000000..871c31d4 --- /dev/null +++ b/Java/Easy/135.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String message = null; + System.out.println(message.length()); + } +} diff --git a/Java/Easy/136.java b/Java/Easy/136.java new file mode 100644 index 00000000..619444e9 --- /dev/null +++ b/Java/Easy/136.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + char c = 'Hello'; + System.out.println(c); + } +} diff --git a/Java/Easy/137.java b/Java/Easy/137.java new file mode 100644 index 00000000..cc9b92f1 --- /dev/null +++ b/Java/Easy/137.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int a = 5; + String s = Integer.toString(a); + System.out.println(s * 2); + } +} diff --git a/Java/Easy/138.java b/Java/Easy/138.java new file mode 100644 index 00000000..5706478f --- /dev/null +++ b/Java/Easy/138.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + double x = Math.abs(); + System.out.println(x); + } +} diff --git a/Java/Easy/139.java b/Java/Easy/139.java new file mode 100644 index 00000000..8115aebb --- /dev/null +++ b/Java/Easy/139.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String[] arr = {"apple", "banana", "orange"}; + System.out.println(arr.size()); + } +} diff --git a/Java/Easy/14.java b/Java/Easy/14.java new file mode 100644 index 00000000..ce681444 --- /dev/null +++ b/Java/Easy/14.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + char ch = 'abc'; + System.out.println(ch); + } +} diff --git a/Java/Easy/140.java b/Java/Easy/140.java new file mode 100644 index 00000000..7ab433d4 --- /dev/null +++ b/Java/Easy/140.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int x = 5 / 1; + System.out.println(x); + } +} diff --git a/Java/Easy/141.java b/Java/Easy/141.java new file mode 100644 index 00000000..95d1f92f --- /dev/null +++ b/Java/Easy/141.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int a = 10; + String s = (String) a; + System.out.println(s); + } +} diff --git a/Java/Easy/142.java b/Java/Easy/142.java new file mode 100644 index 00000000..24859931 --- /dev/null +++ b/Java/Easy/142.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + int a = 10; + Integer b = null; + int result = a + b; + System.out.println(result); + } +} diff --git a/Java/Easy/143.java b/Java/Easy/143.java new file mode 100644 index 00000000..11befc8a --- /dev/null +++ b/Java/Easy/143.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] numbers = {1, 2, 3}; + System.out.println(numbers(0)); + } +} diff --git a/Java/Easy/144.java b/Java/Easy/144.java new file mode 100644 index 00000000..7a948054 --- /dev/null +++ b/Java/Easy/144.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int a = 10; + double result = a / 1; + System.out.println(result); + } +} diff --git a/Java/Easy/145.java b/Java/Easy/145.java new file mode 100644 index 00000000..05eeb233 --- /dev/null +++ b/Java/Easy/145.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + String s = "hello"; + s.concat("world"); + System.out.println(s); + } +} diff --git a/Java/Easy/146.java b/Java/Easy/146.java new file mode 100644 index 00000000..09e5ded9 --- /dev/null +++ b/Java/Easy/146.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + int x = 5; + if (x > 0) + System.out.println("Positive"); + System.out.println("Always printed"); + } +} diff --git a/Java/Easy/147.java b/Java/Easy/147.java new file mode 100644 index 00000000..9237bea8 --- /dev/null +++ b/Java/Easy/147.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] arr = new int[3]{1, 2, 3}; + System.out.println(arr[0]); + } +} diff --git a/Java/Easy/148.java b/Java/Easy/148.java new file mode 100644 index 00000000..01b3cc04 --- /dev/null +++ b/Java/Easy/148.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String name; + System.out.println(name); + } +} diff --git a/Java/Easy/149.java b/Java/Easy/149.java new file mode 100644 index 00000000..093ac887 --- /dev/null +++ b/Java/Easy/149.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + double x = 5.0; + int result = x; + System.out.println(result); + } +} diff --git a/Java/Easy/15.java b/Java/Easy/15.java new file mode 100644 index 00000000..b52bd268 --- /dev/null +++ b/Java/Easy/15.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + boolean isValid = 0; + System.out.println(isValid); + } +} diff --git a/Java/Easy/150.java b/Java/Easy/150.java new file mode 100644 index 00000000..f9054c84 --- /dev/null +++ b/Java/Easy/150.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + int num = 10; + if (num = 10) { + System.out.println("Number is 10"); + } + } +} diff --git a/Java/Easy/151.java b/Java/Easy/151.java new file mode 100644 index 00000000..c7463fec --- /dev/null +++ b/Java/Easy/151.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + int[] arr = new int[3]; + for (int i : arr) { + arr[i] = i * 2; + } + } +} diff --git a/Java/Easy/152.java b/Java/Easy/152.java new file mode 100644 index 00000000..b5b159a6 --- /dev/null +++ b/Java/Easy/152.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] arr = {1, 2, 3}; + arr[3] = 10; + } +} diff --git a/Java/Easy/153.java b/Java/Easy/153.java new file mode 100644 index 00000000..8b5c3d5f --- /dev/null +++ b/Java/Easy/153.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int a = 5; + System.out.println(a = 10); + } +} diff --git a/Java/Easy/154.java b/Java/Easy/154.java new file mode 100644 index 00000000..ea004627 --- /dev/null +++ b/Java/Easy/154.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + int a = 10; + int b = 0; + int result = a / b; + System.out.println(result); + } +} diff --git a/Java/Easy/155.java b/Java/Easy/155.java new file mode 100644 index 00000000..f51f5106 --- /dev/null +++ b/Java/Easy/155.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int x = 10; + System.out.println(x.equals(10)); + } +} diff --git a/Java/Easy/156.java b/Java/Easy/156.java new file mode 100644 index 00000000..34ee1940 --- /dev/null +++ b/Java/Easy/156.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + double x = 10 / 0; + System.out.println(x); + } +} diff --git a/Java/Easy/157.java b/Java/Easy/157.java new file mode 100644 index 00000000..a9328518 --- /dev/null +++ b/Java/Easy/157.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + String text = "Java"; + char firstChar = text[0]; + System.out.println(firstChar); + } +} diff --git a/Java/Easy/158.java b/Java/Easy/158.java new file mode 100644 index 00000000..b943c481 --- /dev/null +++ b/Java/Easy/158.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int x = 5; + System.out.println(x ? "Positive" : "Negative"); + } +} diff --git a/Java/Easy/159.java b/Java/Easy/159.java new file mode 100644 index 00000000..81668ff7 --- /dev/null +++ b/Java/Easy/159.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + String str = "123"; + int number = Integer.toInt(str); + System.out.println(number); + } +} diff --git a/Java/Easy/16.java b/Java/Easy/16.java new file mode 100644 index 00000000..9eb00157 --- /dev/null +++ b/Java/Easy/16.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + int a = 5; + int b = 10; + System.out.println(a > b ? "Greater" : "Smaller"); + else System.out.println("Equal"); + } +} diff --git a/Java/Easy/160.java b/Java/Easy/160.java new file mode 100644 index 00000000..a5467a36 --- /dev/null +++ b/Java/Easy/160.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] arr = {1, 2, 3}; + System.out.println(arr(0)); + } +} diff --git a/Java/Easy/161.java b/Java/Easy/161.java new file mode 100644 index 00000000..80218687 --- /dev/null +++ b/Java/Easy/161.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + boolean isTrue = false; + if (isTrue = true) { + System.out.println("True"); + } + } +} diff --git a/Java/Easy/162.java b/Java/Easy/162.java new file mode 100644 index 00000000..15f54456 --- /dev/null +++ b/Java/Easy/162.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + int a = 10; + float b = 10.5; + int c = a + b; + System.out.println(c); + } +} diff --git a/Java/Easy/163.java b/Java/Easy/163.java new file mode 100644 index 00000000..b2a35c78 --- /dev/null +++ b/Java/Easy/163.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String text = "Hello"; + System.out.println(text.subString(1, 4)); + } +} diff --git a/Java/Easy/164.java b/Java/Easy/164.java new file mode 100644 index 00000000..dc039dae --- /dev/null +++ b/Java/Easy/164.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] arr = new int[3]; + arr.length(); + } +} diff --git a/Java/Easy/165.java b/Java/Easy/165.java new file mode 100644 index 00000000..e8a234b3 --- /dev/null +++ b/Java/Easy/165.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int a = 5; + System.out.println(a++ + ++a); + } +} diff --git a/Java/Easy/166.java b/Java/Easy/166.java new file mode 100644 index 00000000..d6255ff3 --- /dev/null +++ b/Java/Easy/166.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + List list = new ArrayList<>(); + list.add("Alice"); + System.out.println(list[0]); + } +} diff --git a/Java/Easy/167.java b/Java/Easy/167.java new file mode 100644 index 00000000..290a780e --- /dev/null +++ b/Java/Easy/167.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + String text = "apple"; + text.charAt(5); + System.out.println(text); + } +} diff --git a/Java/Easy/168.java b/Java/Easy/168.java new file mode 100644 index 00000000..86048e86 --- /dev/null +++ b/Java/Easy/168.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + double value = 1 / 2; + System.out.println(value); + } +} diff --git a/Java/Easy/169.java b/Java/Easy/169.java new file mode 100644 index 00000000..2fd4c142 --- /dev/null +++ b/Java/Easy/169.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] numbers = {1, 2, 3}; + System.out.println(Arrays.toString(numbers)); + } +} diff --git a/Java/Easy/17.java b/Java/Easy/17.java new file mode 100644 index 00000000..b1f4b533 --- /dev/null +++ b/Java/Easy/17.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int value = null; + System.out.println(value); + } +} diff --git a/Java/Easy/170.java b/Java/Easy/170.java new file mode 100644 index 00000000..a423f378 --- /dev/null +++ b/Java/Easy/170.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + for (int i = 0; i++) { + System.out.println(i); + } + } +} diff --git a/Java/Easy/171.java b/Java/Easy/171.java new file mode 100644 index 00000000..06724785 --- /dev/null +++ b/Java/Easy/171.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String name = "John"; + System.out.println(name.indexOf()); + } +} diff --git a/Java/Easy/172.java b/Java/Easy/172.java new file mode 100644 index 00000000..7defb279 --- /dev/null +++ b/Java/Easy/172.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int a = 5; + boolean b = (a = 10); + System.out.println(b); + } +} diff --git a/Java/Easy/173.java b/Java/Easy/173.java new file mode 100644 index 00000000..4e1e7f2b --- /dev/null +++ b/Java/Easy/173.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String text = null; + System.out.println(text.isEmpty()); + } +} diff --git a/Java/Easy/174.java b/Java/Easy/174.java new file mode 100644 index 00000000..185367f3 --- /dev/null +++ b/Java/Easy/174.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int a = 5; + String result = Integer.toInt(a); + System.out.println(result); + } +} diff --git a/Java/Easy/175.java b/Java/Easy/175.java new file mode 100644 index 00000000..6377408b --- /dev/null +++ b/Java/Easy/175.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int x = 10; + System.out.println((double) x / 0); + } +} diff --git a/Java/Easy/176.java b/Java/Easy/176.java new file mode 100644 index 00000000..80527d07 --- /dev/null +++ b/Java/Easy/176.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int a = 10; + System.out.println(a instanceof Integer); + } +} diff --git a/Java/Easy/177.java b/Java/Easy/177.java new file mode 100644 index 00000000..883668f1 --- /dev/null +++ b/Java/Easy/177.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + boolean flag = true; + if (flag = false) { + System.out.println("True"); + } + } +} diff --git a/Java/Easy/178.java b/Java/Easy/178.java new file mode 100644 index 00000000..88c65db6 --- /dev/null +++ b/Java/Easy/178.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String str = 100; + System.out.println(str); + } +} diff --git a/Java/Easy/179.java b/Java/Easy/179.java new file mode 100644 index 00000000..229f7721 --- /dev/null +++ b/Java/Easy/179.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + List list = new ArrayList<>(); + list.add("Hello"); + list.add(5); + } +} diff --git a/Java/Easy/18.java b/Java/Easy/18.java new file mode 100644 index 00000000..6086a9e1 --- /dev/null +++ b/Java/Easy/18.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + Integer x = 1000; + if (x == 1000) { + System.out.println("Equal"); + } + } +} diff --git a/Java/Easy/180.java b/Java/Easy/180.java new file mode 100644 index 00000000..a12070e0 --- /dev/null +++ b/Java/Easy/180.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int x = 5; + String result = Integer.parseInt(x); + System.out.println(result); + } +} diff --git a/Java/Easy/181.java b/Java/Easy/181.java new file mode 100644 index 00000000..248a6787 --- /dev/null +++ b/Java/Easy/181.java @@ -0,0 +1,5 @@ +class Main { + public static void main(String[] args) { + System.out.println(Math.pow(2)); + } +} diff --git a/Java/Easy/182.java b/Java/Easy/182.java new file mode 100644 index 00000000..7ed2dc10 --- /dev/null +++ b/Java/Easy/182.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + String text = "Java"; + text.replace("a", 'o'); + System.out.println(text); + } +} diff --git a/Java/Easy/183.java b/Java/Easy/183.java new file mode 100644 index 00000000..6328d1b9 --- /dev/null +++ b/Java/Easy/183.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + String[] arr = {"one", "two", "three"}; + for (String i = arr) { + System.out.println(i); + } + } +} diff --git a/Java/Easy/184.java b/Java/Easy/184.java new file mode 100644 index 00000000..cbcae932 --- /dev/null +++ b/Java/Easy/184.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + String text = "hello"; + text.charAt(10); + System.out.println(text); + } +} diff --git a/Java/Easy/185.java b/Java/Easy/185.java new file mode 100644 index 00000000..32b60a0b --- /dev/null +++ b/Java/Easy/185.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int a = 5; + String result = a.toString(); + System.out.println(result); + } +} diff --git a/Java/Easy/186.java b/Java/Easy/186.java new file mode 100644 index 00000000..0b2ed84c --- /dev/null +++ b/Java/Easy/186.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int a = 5; + int b = 10; + System.out.println(a = b ? "Equal" : "Not Equal"); + } +} diff --git a/Java/Easy/187.java b/Java/Easy/187.java new file mode 100644 index 00000000..9990364d --- /dev/null +++ b/Java/Easy/187.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String[] items = {"Apple", "Orange"}; + System.out.println(items[-1]); + } +} diff --git a/Java/Easy/188.java b/Java/Easy/188.java new file mode 100644 index 00000000..f9b87949 --- /dev/null +++ b/Java/Easy/188.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + int[] arr = new int[5]; + for (int i = 0; i < arr.size(); i++) { + System.out.println(arr[i]); + } + } +} diff --git a/Java/Easy/189.java b/Java/Easy/189.java new file mode 100644 index 00000000..74424378 --- /dev/null +++ b/Java/Easy/189.java @@ -0,0 +1,10 @@ +class Main { + public static void main(String[] args) { + int a = 5; + if (a > 10) + System.out.println("a is greater than 10"); + else + System.out.println("a is less than 10"); + System.out.println("This will always print"); + } +} diff --git a/Java/Easy/19.java b/Java/Easy/19.java new file mode 100644 index 00000000..f67a3ee8 --- /dev/null +++ b/Java/Easy/19.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int[] arr = new int[5]; + arr.add(10); + System.out.println(arr[0]); + } +} diff --git a/Java/Easy/190.java b/Java/Easy/190.java new file mode 100644 index 00000000..ce08592f --- /dev/null +++ b/Java/Easy/190.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int x = Math.max(); + System.out.println(x); + } +} diff --git a/Java/Easy/191.java b/Java/Easy/191.java new file mode 100644 index 00000000..4d3d77be --- /dev/null +++ b/Java/Easy/191.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int a = 5; + double b = 10.5; + System.out.println(a + (String) b); + } +} diff --git a/Java/Easy/192.java b/Java/Easy/192.java new file mode 100644 index 00000000..6d3cd37a --- /dev/null +++ b/Java/Easy/192.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + double x = 5 / 2; + System.out.println(x); + } +} diff --git a/Java/Easy/193.java b/Java/Easy/193.java new file mode 100644 index 00000000..7f497598 --- /dev/null +++ b/Java/Easy/193.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String[] arr = {"A", "B", "C"}; + System.out.println(arr.length()); + } +} diff --git a/Java/Easy/194.java b/Java/Easy/194.java new file mode 100644 index 00000000..899711c3 --- /dev/null +++ b/Java/Easy/194.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] numbers = new int[5]; + System.out.println(numbers.size()); + } +} diff --git a/Java/Easy/195.java b/Java/Easy/195.java new file mode 100644 index 00000000..968222f0 --- /dev/null +++ b/Java/Easy/195.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + List numbers = new ArrayList<>(); + System.out.println(numbers); + } +} diff --git a/Java/Easy/196.java b/Java/Easy/196.java new file mode 100644 index 00000000..aac002c5 --- /dev/null +++ b/Java/Easy/196.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + String message = "Hello"; + message.concat("World"); + System.out.println(message); + } +} diff --git a/Java/Easy/197.java b/Java/Easy/197.java new file mode 100644 index 00000000..0cd4ebb1 --- /dev/null +++ b/Java/Easy/197.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int x = 100; + System.out.println(x ? "Yes" : "No"); + } +} diff --git a/Java/Easy/198.java b/Java/Easy/198.java new file mode 100644 index 00000000..13bc35b2 --- /dev/null +++ b/Java/Easy/198.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int[] nums = new int[5]; + nums.add(10); + System.out.println(nums[0]); + } +} diff --git a/Java/Easy/199.java b/Java/Easy/199.java new file mode 100644 index 00000000..1acc4da3 --- /dev/null +++ b/Java/Easy/199.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String text = "abc"; + System.out.println(text.charAt(5)); + } +} diff --git a/Java/Easy/2.java b/Java/Easy/2.java new file mode 100644 index 00000000..e8c88fec --- /dev/null +++ b/Java/Easy/2.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] numbers = {1, 2, 3}; + System.out.println(numbers[0]); + } +} diff --git a/Java/Easy/20.java b/Java/Easy/20.java new file mode 100644 index 00000000..5ec7f159 --- /dev/null +++ b/Java/Easy/20.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] numbers = new int[-10]; + System.out.println(numbers.length); + } +} diff --git a/Java/Easy/200.java b/Java/Easy/200.java new file mode 100644 index 00000000..e516a5ff --- /dev/null +++ b/Java/Easy/200.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int x = 10; + double y = 0; + System.out.println(x / y); + } +} diff --git a/Java/Easy/201.java b/Java/Easy/201.java new file mode 100644 index 00000000..dcaf2e6c --- /dev/null +++ b/Java/Easy/201.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String[] fruits = new String[5]; + fruits[5] = "Apple"; + } +} diff --git a/Java/Easy/202.java b/Java/Easy/202.java new file mode 100644 index 00000000..e6b16815 --- /dev/null +++ b/Java/Easy/202.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + boolean result = (5 == 5 ? "true" : "false"); + System.out.println(result); + } +} diff --git a/Java/Easy/203.java b/Java/Easy/203.java new file mode 100644 index 00000000..8f08c3a7 --- /dev/null +++ b/Java/Easy/203.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + int a = 5; + double b = 0; + int result = a / b; + System.out.println(result); + } +} diff --git a/Java/Easy/204.java b/Java/Easy/204.java new file mode 100644 index 00000000..5575f531 --- /dev/null +++ b/Java/Easy/204.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + double result = Math.pow(2); + System.out.println(result); + } +} diff --git a/Java/Easy/205.java b/Java/Easy/205.java new file mode 100644 index 00000000..c01de6f0 --- /dev/null +++ b/Java/Easy/205.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int a = 5; + System.out.println(a + " " + Math.pow(a, 2)); + } +} diff --git a/Java/Easy/206.java b/Java/Easy/206.java new file mode 100644 index 00000000..1b0182c3 --- /dev/null +++ b/Java/Easy/206.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + List names = new ArrayList<>(); + names.add("Alice", "Bob"); + System.out.println(names); + } +} diff --git a/Java/Easy/207.java b/Java/Easy/207.java new file mode 100644 index 00000000..bb94d139 --- /dev/null +++ b/Java/Easy/207.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int x = 10; + System.out.println("x is " x); + } +} diff --git a/Java/Easy/208.java b/Java/Easy/208.java new file mode 100644 index 00000000..20c6988a --- /dev/null +++ b/Java/Easy/208.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + char ch = "Hello"; + System.out.println(ch); + } +} diff --git a/Java/Easy/209.java b/Java/Easy/209.java new file mode 100644 index 00000000..465361ab --- /dev/null +++ b/Java/Easy/209.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] arr = new int[-5]; + System.out.println(arr.length); + } +} diff --git a/Java/Easy/21.java b/Java/Easy/21.java new file mode 100644 index 00000000..d008d0db --- /dev/null +++ b/Java/Easy/21.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + for (int i = 0; i < 10, i++) { + System.out.println(i); + } + } +} diff --git a/Java/Easy/210.java b/Java/Easy/210.java new file mode 100644 index 00000000..d671e65c --- /dev/null +++ b/Java/Easy/210.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + double value = 3.14; + int x = value; + System.out.println(x); + } +} diff --git a/Java/Easy/211.java b/Java/Easy/211.java new file mode 100644 index 00000000..f7f8f9a2 --- /dev/null +++ b/Java/Easy/211.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int x = 5; + if (x == 5); + System.out.println("x is 5"); + } +} diff --git a/Java/Easy/212.java b/Java/Easy/212.java new file mode 100644 index 00000000..90c5f0b8 --- /dev/null +++ b/Java/Easy/212.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int a = "100"; + System.out.println(a); + } +} diff --git a/Java/Easy/213.java b/Java/Easy/213.java new file mode 100644 index 00000000..bdcc1f81 --- /dev/null +++ b/Java/Easy/213.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String[] arr = new String[3]; + System.out.println(arr.size()); + } +} diff --git a/Java/Easy/214.java b/Java/Easy/214.java new file mode 100644 index 00000000..e1f0b6cc --- /dev/null +++ b/Java/Easy/214.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + int a = 5; + double b = 10.5; + int c = a + b; + System.out.println(c); + } +} diff --git a/Java/Easy/215.java b/Java/Easy/215.java new file mode 100644 index 00000000..97199118 --- /dev/null +++ b/Java/Easy/215.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String text = "abc"; + System.out.println(text.substring(4)); + } +} diff --git a/Java/Easy/216.java b/Java/Easy/216.java new file mode 100644 index 00000000..f18ab67b --- /dev/null +++ b/Java/Easy/216.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String[] arr = new String[] {"A", "B", "C"}; + System.out.println(arr.get(0)); + } +} diff --git a/Java/Easy/217.java b/Java/Easy/217.java new file mode 100644 index 00000000..9cb16a06 --- /dev/null +++ b/Java/Easy/217.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + String text = "hello"; + char ch = text.charAt(6); + System.out.println(ch); + } +} diff --git a/Java/Easy/218.java b/Java/Easy/218.java new file mode 100644 index 00000000..1d4e2b15 --- /dev/null +++ b/Java/Easy/218.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int x = 5; + double result = x / 0; + System.out.println(result); + } +} diff --git a/Java/Easy/219.java b/Java/Easy/219.java new file mode 100644 index 00000000..1c89aa9f --- /dev/null +++ b/Java/Easy/219.java @@ -0,0 +1,5 @@ +class Main { + public static void main(String[] args) { + System.out.println(Math.sqrt(-1)); + } +} diff --git a/Java/Easy/22.java b/Java/Easy/22.java new file mode 100644 index 00000000..938c9b8f --- /dev/null +++ b/Java/Easy/22.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] arr = new int[5]; + System.out.println(arr.size()); + } +} diff --git a/Java/Easy/220.java b/Java/Easy/220.java new file mode 100644 index 00000000..7d8bbe77 --- /dev/null +++ b/Java/Easy/220.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + double x = 5 / 0; + System.out.println(x); + } +} diff --git a/Java/Easy/221.java b/Java/Easy/221.java new file mode 100644 index 00000000..b5b159a6 --- /dev/null +++ b/Java/Easy/221.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] arr = {1, 2, 3}; + arr[3] = 10; + } +} diff --git a/Java/Easy/222.java b/Java/Easy/222.java new file mode 100644 index 00000000..79c1713b --- /dev/null +++ b/Java/Easy/222.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String name = null; + System.out.println(name.isEmpty()); + } +} diff --git a/Java/Easy/223.java b/Java/Easy/223.java new file mode 100644 index 00000000..0b82455c --- /dev/null +++ b/Java/Easy/223.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + String text = "Java"; + text.toUppercase(); + System.out.println(text); + } +} diff --git a/Java/Easy/224.java b/Java/Easy/224.java new file mode 100644 index 00000000..94896f15 --- /dev/null +++ b/Java/Easy/224.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int a = 5; + boolean result = (a = 10); + System.out.println(result); + } +} diff --git a/Java/Easy/225.java b/Java/Easy/225.java new file mode 100644 index 00000000..4c3c7c80 --- /dev/null +++ b/Java/Easy/225.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + String name = "Alice"; + char letter = name.charAt(10); + System.out.println(letter); + } +} diff --git a/Java/Easy/226.java b/Java/Easy/226.java new file mode 100644 index 00000000..6d3cd37a --- /dev/null +++ b/Java/Easy/226.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + double x = 5 / 2; + System.out.println(x); + } +} diff --git a/Java/Easy/227.java b/Java/Easy/227.java new file mode 100644 index 00000000..982768c6 --- /dev/null +++ b/Java/Easy/227.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int x = null; + System.out.println(x); + } +} diff --git a/Java/Easy/228.java b/Java/Easy/228.java new file mode 100644 index 00000000..5e688afa --- /dev/null +++ b/Java/Easy/228.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String message = "Hello World"; + System.out.println(message.charAt(11)); + } +} diff --git a/Java/Easy/229.java b/Java/Easy/229.java new file mode 100644 index 00000000..dc039dae --- /dev/null +++ b/Java/Easy/229.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] arr = new int[3]; + arr.length(); + } +} diff --git a/Java/Easy/23.java b/Java/Easy/23.java new file mode 100644 index 00000000..9ac8a60b --- /dev/null +++ b/Java/Easy/23.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int a = "10"; + System.out.println(a); + } +} diff --git a/Java/Easy/230.java b/Java/Easy/230.java new file mode 100644 index 00000000..bc2af979 --- /dev/null +++ b/Java/Easy/230.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + List fruits = new ArrayList<>(); + fruits.add("Apple"); + fruits(0) = "Banana"; + } +} diff --git a/Java/Easy/231.java b/Java/Easy/231.java new file mode 100644 index 00000000..cf4f0e4a --- /dev/null +++ b/Java/Easy/231.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + String text = "Java"; + text.replace('a', "b"); + System.out.println(text); + } +} diff --git a/Java/Easy/232.java b/Java/Easy/232.java new file mode 100644 index 00000000..d32c00d9 --- /dev/null +++ b/Java/Easy/232.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + double value = Math.sqrt(25); + int result = value; + System.out.println(result); + } +} diff --git a/Java/Easy/233.java b/Java/Easy/233.java new file mode 100644 index 00000000..24859931 --- /dev/null +++ b/Java/Easy/233.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + int a = 10; + Integer b = null; + int result = a + b; + System.out.println(result); + } +} diff --git a/Java/Easy/234.java b/Java/Easy/234.java new file mode 100644 index 00000000..9faa7094 --- /dev/null +++ b/Java/Easy/234.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String s = "Java"; + System.out.println(s.charAt(4)); + } +} diff --git a/Java/Easy/235.java b/Java/Easy/235.java new file mode 100644 index 00000000..bf8de9e2 --- /dev/null +++ b/Java/Easy/235.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int x = 10; + System.out.println(x ? "Yes" : "No"); + } +} diff --git a/Java/Easy/236.java b/Java/Easy/236.java new file mode 100644 index 00000000..11befc8a --- /dev/null +++ b/Java/Easy/236.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] numbers = {1, 2, 3}; + System.out.println(numbers(0)); + } +} diff --git a/Java/Easy/237.java b/Java/Easy/237.java new file mode 100644 index 00000000..3f154c9c --- /dev/null +++ b/Java/Easy/237.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + double result = Math.pow(5); + System.out.println(result); + } +} diff --git a/Java/Easy/238.java b/Java/Easy/238.java new file mode 100644 index 00000000..34efc881 --- /dev/null +++ b/Java/Easy/238.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + String str = null; + if (str.equals("Hello")) { + System.out.println("Hello"); + } + } +} diff --git a/Java/Easy/239.java b/Java/Easy/239.java new file mode 100644 index 00000000..80527d07 --- /dev/null +++ b/Java/Easy/239.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int a = 10; + System.out.println(a instanceof Integer); + } +} diff --git a/Java/Easy/24.java b/Java/Easy/24.java new file mode 100644 index 00000000..13bc35b2 --- /dev/null +++ b/Java/Easy/24.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int[] nums = new int[5]; + nums.add(10); + System.out.println(nums[0]); + } +} diff --git a/Java/Easy/240.java b/Java/Easy/240.java new file mode 100644 index 00000000..87da08b4 --- /dev/null +++ b/Java/Easy/240.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + double num = 5 / 2; + System.out.println(num); + } +} diff --git a/Java/Easy/241.java b/Java/Easy/241.java new file mode 100644 index 00000000..d2cc5a18 --- /dev/null +++ b/Java/Easy/241.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String[] arr = {"A", "B", "C"}; + arr[3] = "D"; + } +} diff --git a/Java/Easy/242.java b/Java/Easy/242.java new file mode 100644 index 00000000..9237bea8 --- /dev/null +++ b/Java/Easy/242.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] arr = new int[3]{1, 2, 3}; + System.out.println(arr[0]); + } +} diff --git a/Java/Easy/243.java b/Java/Easy/243.java new file mode 100644 index 00000000..bd60bdb0 --- /dev/null +++ b/Java/Easy/243.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String message = "Hello, World!"; + System.out.println(message.substring(1, 20)); + } +} diff --git a/Java/Easy/244.java b/Java/Easy/244.java new file mode 100644 index 00000000..f85cd68d --- /dev/null +++ b/Java/Easy/244.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int x = Math.abs(); + System.out.println(x); + } +} diff --git a/Java/Easy/245.java b/Java/Easy/245.java new file mode 100644 index 00000000..b2a35c78 --- /dev/null +++ b/Java/Easy/245.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String text = "Hello"; + System.out.println(text.subString(1, 4)); + } +} diff --git a/Java/Easy/246.java b/Java/Easy/246.java new file mode 100644 index 00000000..4a50e924 --- /dev/null +++ b/Java/Easy/246.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + String message = "Hello"; + message.replace('e', "a"); + System.out.println(message); + } +} diff --git a/Java/Easy/247.java b/Java/Easy/247.java new file mode 100644 index 00000000..0a30e02f --- /dev/null +++ b/Java/Easy/247.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + String str = null; + if (str.equals("Hello")) { + System.out.println("Text is Hello"); + } + } +} diff --git a/Java/Easy/248.java b/Java/Easy/248.java new file mode 100644 index 00000000..6d3cd37a --- /dev/null +++ b/Java/Easy/248.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + double x = 5 / 2; + System.out.println(x); + } +} diff --git a/Java/Easy/249.java b/Java/Easy/249.java new file mode 100644 index 00000000..b943c481 --- /dev/null +++ b/Java/Easy/249.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int x = 5; + System.out.println(x ? "Positive" : "Negative"); + } +} diff --git a/Java/Easy/25.java b/Java/Easy/25.java new file mode 100644 index 00000000..94ae4a30 --- /dev/null +++ b/Java/Easy/25.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + String name = "John"; + name.toUpperCase; + System.out.println(name); + } +} diff --git a/Java/Easy/250.java b/Java/Easy/250.java new file mode 100644 index 00000000..6a44cb03 --- /dev/null +++ b/Java/Easy/250.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + char c = "A"; + System.out.println(c); + } +} diff --git a/Java/Easy/26.java b/Java/Easy/26.java new file mode 100644 index 00000000..c185927a --- /dev/null +++ b/Java/Easy/26.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int x = 10; + System.out.println(x.toString()); + } +} diff --git a/Java/Easy/27.java b/Java/Easy/27.java new file mode 100644 index 00000000..994e88f0 --- /dev/null +++ b/Java/Easy/27.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + int[] numbers = new int[5]; + for (int i = 0; i <= 5; i++) { + numbers[i] = i; + } + } +} diff --git a/Java/Easy/28.java b/Java/Easy/28.java new file mode 100644 index 00000000..a7fdb458 --- /dev/null +++ b/Java/Easy/28.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int[] arr = new int[5]; + arr[0] = "100"; + System.out.println(arr[0]); + } +} diff --git a/Java/Easy/29.java b/Java/Easy/29.java new file mode 100644 index 00000000..50955080 --- /dev/null +++ b/Java/Easy/29.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int a = 5; + int b = "5"; + System.out.println(a + b); + } +} diff --git a/Java/Easy/3.java b/Java/Easy/3.java new file mode 100644 index 00000000..01b3cc04 --- /dev/null +++ b/Java/Easy/3.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String name; + System.out.println(name); + } +} diff --git a/Java/Easy/30.java b/Java/Easy/30.java new file mode 100644 index 00000000..3b3c4f3a --- /dev/null +++ b/Java/Easy/30.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + double x = Math.sqrt(-1); + System.out.println(x); + } +} diff --git a/Java/Easy/31.java b/Java/Easy/31.java new file mode 100644 index 00000000..8859aebd --- /dev/null +++ b/Java/Easy/31.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int a = 5; + System.out.println(a++ * ++a); + } +} diff --git a/Java/Easy/32.java b/Java/Easy/32.java new file mode 100644 index 00000000..57018eff --- /dev/null +++ b/Java/Easy/32.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int a = 5; + Integer b = null; + System.out.println(a + b); + } +} diff --git a/Java/Easy/33.java b/Java/Easy/33.java new file mode 100644 index 00000000..f00a56ef --- /dev/null +++ b/Java/Easy/33.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String s = "hello"; + System.out.println(s.reverse()); + } +} diff --git a/Java/Easy/34.java b/Java/Easy/34.java new file mode 100644 index 00000000..89fb0590 --- /dev/null +++ b/Java/Easy/34.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int num = 5; + num.equals(5); + } +} diff --git a/Java/Easy/35.java b/Java/Easy/35.java new file mode 100644 index 00000000..0fcb2232 --- /dev/null +++ b/Java/Easy/35.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String name = null; + System.out.println(name.length()); + } +} diff --git a/Java/Easy/36.java b/Java/Easy/36.java new file mode 100644 index 00000000..f9a30f16 --- /dev/null +++ b/Java/Easy/36.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] arr = {1, 2, 3}; + System.out.println(arr.toString()); + } +} diff --git a/Java/Easy/37.java b/Java/Easy/37.java new file mode 100644 index 00000000..12801dd7 --- /dev/null +++ b/Java/Easy/37.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int a = 5; + a++; + System.out.println(++a++); + } +} diff --git a/Java/Easy/38.java b/Java/Easy/38.java new file mode 100644 index 00000000..a74c0f08 --- /dev/null +++ b/Java/Easy/38.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] arr = new int[5]; + System.out.println(arr(0)); + } +} diff --git a/Java/Easy/39.java b/Java/Easy/39.java new file mode 100644 index 00000000..7923e479 --- /dev/null +++ b/Java/Easy/39.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + double x = Math.pow(2,3); + System.out.println(x); + } +} diff --git a/Java/Easy/4.java b/Java/Easy/4.java new file mode 100644 index 00000000..a7fcce57 --- /dev/null +++ b/Java/Easy/4.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + List names = new ArrayList<>(); + names.add("Alice"); + System.out.println(names[0]); + } +} diff --git a/Java/Easy/40.java b/Java/Easy/40.java new file mode 100644 index 00000000..c767dccc --- /dev/null +++ b/Java/Easy/40.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int x = "100"; + System.out.println(x); + } +} diff --git a/Java/Easy/41.java b/Java/Easy/41.java new file mode 100644 index 00000000..9908cfc4 --- /dev/null +++ b/Java/Easy/41.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + List list = new ArrayList<>(); + list.add("apple"); + System.out.println(list[0]); + } +} diff --git a/Java/Easy/42.java b/Java/Easy/42.java new file mode 100644 index 00000000..248a6787 --- /dev/null +++ b/Java/Easy/42.java @@ -0,0 +1,5 @@ +class Main { + public static void main(String[] args) { + System.out.println(Math.pow(2)); + } +} diff --git a/Java/Easy/43.java b/Java/Easy/43.java new file mode 100644 index 00000000..b156edd8 --- /dev/null +++ b/Java/Easy/43.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String s = "Java"; + System.out.println(s.length(5)); + } +} diff --git a/Java/Easy/44.java b/Java/Easy/44.java new file mode 100644 index 00000000..e5aedcf1 --- /dev/null +++ b/Java/Easy/44.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + List items = new ArrayList<>(); + items.add("Item1"); + System.out.println(items(0)); + } +} diff --git a/Java/Easy/45.java b/Java/Easy/45.java new file mode 100644 index 00000000..8e5c132e --- /dev/null +++ b/Java/Easy/45.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + double x = 5.0 / 1.0; + System.out.println(x); + } +} diff --git a/Java/Easy/46.java b/Java/Easy/46.java new file mode 100644 index 00000000..8194d516 --- /dev/null +++ b/Java/Easy/46.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + boolean isTrue = True; + System.out.println(isTrue); + } +} diff --git a/Java/Easy/47.java b/Java/Easy/47.java new file mode 100644 index 00000000..d7ab069c --- /dev/null +++ b/Java/Easy/47.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int a = 5; + int result = Math.pow(a); + System.out.println(result); + } +} diff --git a/Java/Easy/48.java b/Java/Easy/48.java new file mode 100644 index 00000000..80ca4739 --- /dev/null +++ b/Java/Easy/48.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int x = 5 / 0; + System.out.println(x); + } +} diff --git a/Java/Easy/49.java b/Java/Easy/49.java new file mode 100644 index 00000000..624b5bed --- /dev/null +++ b/Java/Easy/49.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + List numbers = new ArrayList<>(); + numbers.add(10); + System.out.println(numbers.get(0)); + } +} diff --git a/Java/Easy/5.java b/Java/Easy/5.java new file mode 100644 index 00000000..2670118f --- /dev/null +++ b/Java/Easy/5.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] arr = {1, 2, 3}; + System.out.println(arr); + } +} diff --git a/Java/Easy/50.java b/Java/Easy/50.java new file mode 100644 index 00000000..d94fb137 --- /dev/null +++ b/Java/Easy/50.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String name = "Java"; + System.out.println(name.indexOf(2)); + } +} diff --git a/Java/Easy/51.java b/Java/Easy/51.java new file mode 100644 index 00000000..6c1438c8 --- /dev/null +++ b/Java/Easy/51.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + int number = 5; + if (number = 5) { + System.out.println("Number is 5"); + } + } +} diff --git a/Java/Easy/52.java b/Java/Easy/52.java new file mode 100644 index 00000000..a9ee81fc --- /dev/null +++ b/Java/Easy/52.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int a = 10; + String s = "Hello"; + } +} diff --git a/Java/Easy/53.java b/Java/Easy/53.java new file mode 100644 index 00000000..5e862589 --- /dev/null +++ b/Java/Easy/53.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] arr = new int[5]; + arr[0] = 10; + } +} diff --git a/Java/Easy/54.java b/Java/Easy/54.java new file mode 100644 index 00000000..b1de45bf --- /dev/null +++ b/Java/Easy/54.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + for (int i = 0; i < 10 i++) { + System.out.println(i); + } + } +} diff --git a/Java/Easy/55.java b/Java/Easy/55.java new file mode 100644 index 00000000..54cf07ae --- /dev/null +++ b/Java/Easy/55.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String greeting = Hello; + System.out.println(greeting); + } +} diff --git a/Java/Easy/56.java b/Java/Easy/56.java new file mode 100644 index 00000000..027e0290 --- /dev/null +++ b/Java/Easy/56.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int x = 1; + double y = x / 0; + System.out.println(y); + } +} diff --git a/Java/Easy/57.java b/Java/Easy/57.java new file mode 100644 index 00000000..54cf07ae --- /dev/null +++ b/Java/Easy/57.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String greeting = Hello; + System.out.println(greeting); + } +} diff --git a/Java/Easy/58.java b/Java/Easy/58.java new file mode 100644 index 00000000..65381694 --- /dev/null +++ b/Java/Easy/58.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + String message = "Hello, World!"; + char c = message.charAt(20); + System.out.println(c); + } +} diff --git a/Java/Easy/59.java b/Java/Easy/59.java new file mode 100644 index 00000000..fe0d3f67 --- /dev/null +++ b/Java/Easy/59.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String[] fruits = {"Apple", "Banana", "Mango"}; + System.out.println(fruits[1]); + } +} diff --git a/Java/Easy/6.java b/Java/Easy/6.java new file mode 100644 index 00000000..5d22ef9e --- /dev/null +++ b/Java/Easy/6.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String s = "abc"; + System.out.println(s.charAt(5)); + } +} diff --git a/Java/Easy/60.java b/Java/Easy/60.java new file mode 100644 index 00000000..a91aad94 --- /dev/null +++ b/Java/Easy/60.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int a = 10, b = 0; + int result = a / b; + System.out.println(result); + } +} diff --git a/Java/Easy/61.java b/Java/Easy/61.java new file mode 100644 index 00000000..6f9c6d49 --- /dev/null +++ b/Java/Easy/61.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + int[] arr = new int[5]; + for (int i : arr) { + arr[i] = i * 2; + } + } +} diff --git a/Java/Easy/62.java b/Java/Easy/62.java new file mode 100644 index 00000000..d06be962 --- /dev/null +++ b/Java/Easy/62.java @@ -0,0 +1,9 @@ +class Main { + public static void main(String[] args) { + int x = 10; + while x > 0 { + System.out.println(x); + x--; + } + } +} diff --git a/Java/Easy/63.java b/Java/Easy/63.java new file mode 100644 index 00000000..6636055b --- /dev/null +++ b/Java/Easy/63.java @@ -0,0 +1,11 @@ +class Main { + public static void main(String[] args) { + int x = 5; + switch (x) { + case 5: + System.out.println("Five"); + default: + System.out.println("Default case"); + } + } +} diff --git a/Java/Easy/64.java b/Java/Easy/64.java new file mode 100644 index 00000000..76bf5189 --- /dev/null +++ b/Java/Easy/64.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] arr = new int[10]; + System.out.println(arr.length()); + } +} diff --git a/Java/Easy/65.java b/Java/Easy/65.java new file mode 100644 index 00000000..edfc1ba1 --- /dev/null +++ b/Java/Easy/65.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + double pi = 3.14159; + double radius = 5.0; + double area = Math.pi * radius * radius; + System.out.println(area); + } +} diff --git a/Java/Easy/66.java b/Java/Easy/66.java new file mode 100644 index 00000000..1440d9e1 --- /dev/null +++ b/Java/Easy/66.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int a = 5; + int b = 10; + System.out.println(a + b); + } +} diff --git a/Java/Easy/67.java b/Java/Easy/67.java new file mode 100644 index 00000000..c3409845 --- /dev/null +++ b/Java/Easy/67.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String str = null; + System.out.println(str.length()); + } +} diff --git a/Java/Easy/68.java b/Java/Easy/68.java new file mode 100644 index 00000000..003c7c4d --- /dev/null +++ b/Java/Easy/68.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + char ch = "A"; + System.out.println(ch); + } +} diff --git a/Java/Easy/69.java b/Java/Easy/69.java new file mode 100644 index 00000000..f51f5106 --- /dev/null +++ b/Java/Easy/69.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int x = 10; + System.out.println(x.equals(10)); + } +} diff --git a/Java/Easy/7.java b/Java/Easy/7.java new file mode 100644 index 00000000..3d113ded --- /dev/null +++ b/Java/Easy/7.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] nums = new int[-5]; + System.out.println(nums.length); + } +} diff --git a/Java/Easy/70.java b/Java/Easy/70.java new file mode 100644 index 00000000..97285f8b --- /dev/null +++ b/Java/Easy/70.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + String s = "hello"; + s.toUppercase(); + System.out.println(s); + } +} diff --git a/Java/Easy/71.java b/Java/Easy/71.java new file mode 100644 index 00000000..cded88fb --- /dev/null +++ b/Java/Easy/71.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int result = 5 + ; + System.out.println(result); + } +} diff --git a/Java/Easy/72.java b/Java/Easy/72.java new file mode 100644 index 00000000..20e27221 --- /dev/null +++ b/Java/Easy/72.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + String[] names = {"John", "Doe"}; + for (int i = 0; i < names.size(); i++) { + System.out.println(names[i]); + } + } +} diff --git a/Java/Easy/73.java b/Java/Easy/73.java new file mode 100644 index 00000000..a7f0fd5b --- /dev/null +++ b/Java/Easy/73.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + int x = 5; + double y = 0.0; + double result = x % y; + System.out.println(result); + } +} diff --git a/Java/Easy/74.java b/Java/Easy/74.java new file mode 100644 index 00000000..68bd526e --- /dev/null +++ b/Java/Easy/74.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int a = 100; + byte b = a; + System.out.println(b); + } +} diff --git a/Java/Easy/75.java b/Java/Easy/75.java new file mode 100644 index 00000000..45f002ab --- /dev/null +++ b/Java/Easy/75.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + int a = 10; + Integer b = null; + int c = b + a; + System.out.println(c); + } +} diff --git a/Java/Easy/76.java b/Java/Easy/76.java new file mode 100644 index 00000000..db30001f --- /dev/null +++ b/Java/Easy/76.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + for (int i = 0; i < 10; i++); + System.out.println(i); + } +} diff --git a/Java/Easy/77.java b/Java/Easy/77.java new file mode 100644 index 00000000..3b3c4f3a --- /dev/null +++ b/Java/Easy/77.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + double x = Math.sqrt(-1); + System.out.println(x); + } +} diff --git a/Java/Easy/78.java b/Java/Easy/78.java new file mode 100644 index 00000000..2ae3169b --- /dev/null +++ b/Java/Easy/78.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + Object obj = "Hello"; + int num = (int) obj; + System.out.println(num); + } +} diff --git a/Java/Easy/79.java b/Java/Easy/79.java new file mode 100644 index 00000000..9ac8a60b --- /dev/null +++ b/Java/Easy/79.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int a = "10"; + System.out.println(a); + } +} diff --git a/Java/Easy/8.java b/Java/Easy/8.java new file mode 100644 index 00000000..713afb66 --- /dev/null +++ b/Java/Easy/8.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + int a = 5; + int b = 2; + double result = Math.pow(a,b); + System.out.println(result); + } +} diff --git a/Java/Easy/80.java b/Java/Easy/80.java new file mode 100644 index 00000000..4f4502f6 --- /dev/null +++ b/Java/Easy/80.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int a = 10; + a++; + System.out.println(a++); + } +} diff --git a/Java/Easy/81.java b/Java/Easy/81.java new file mode 100644 index 00000000..e184b67c --- /dev/null +++ b/Java/Easy/81.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + String s = "hello"; + s = null; + System.out.println(s.toUpperCase()); + } +} diff --git a/Java/Easy/82.java b/Java/Easy/82.java new file mode 100644 index 00000000..dc1ce17b --- /dev/null +++ b/Java/Easy/82.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int a = 5; + String s = Integer.parseInt(a); + System.out.println(s); + } +} diff --git a/Java/Easy/83.java b/Java/Easy/83.java new file mode 100644 index 00000000..cbc6b127 --- /dev/null +++ b/Java/Easy/83.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + String s = "Java"; + s.replace('a', "o"); + System.out.println(s); + } +} diff --git a/Java/Easy/84.java b/Java/Easy/84.java new file mode 100644 index 00000000..dde403c5 --- /dev/null +++ b/Java/Easy/84.java @@ -0,0 +1,9 @@ +class Main { + public static void main(String[] args) { + int a = 0; + while (a = 10) { + System.out.println(a); + a++; + } + } +} diff --git a/Java/Easy/85.java b/Java/Easy/85.java new file mode 100644 index 00000000..a50d7082 --- /dev/null +++ b/Java/Easy/85.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String[] fruits = new String[]{"Apple", "Orange", "Banana"}; + System.out.println(fruits(0)); + } +} diff --git a/Java/Easy/86.java b/Java/Easy/86.java new file mode 100644 index 00000000..d28f68dd --- /dev/null +++ b/Java/Easy/86.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + int a = 1; + do { + System.out.println(a); + } while a < 10; + } +} diff --git a/Java/Easy/87.java b/Java/Easy/87.java new file mode 100644 index 00000000..16b612d2 --- /dev/null +++ b/Java/Easy/87.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String message = 'Hello World'; + System.out.println(message); + } +} diff --git a/Java/Easy/88.java b/Java/Easy/88.java new file mode 100644 index 00000000..fbdaea07 --- /dev/null +++ b/Java/Easy/88.java @@ -0,0 +1,5 @@ +class Main { + public static void main(String[] args) { + System.out.println("Sum of 5 and 10 is: " + 5 + 10); + } +} diff --git a/Java/Easy/89.java b/Java/Easy/89.java new file mode 100644 index 00000000..e6d97677 --- /dev/null +++ b/Java/Easy/89.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] nums = {1, 2, 3}; + System.out.println(nums[-1]); + } +} diff --git a/Java/Easy/9.java b/Java/Easy/9.java new file mode 100644 index 00000000..adf3afbf --- /dev/null +++ b/Java/Easy/9.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int[] numbers = new int[3]; + numbers[0] = 5; + numbers[3] = 10; + } +} diff --git a/Java/Easy/90.java b/Java/Easy/90.java new file mode 100644 index 00000000..6bd6f77f --- /dev/null +++ b/Java/Easy/90.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] arr = new int[5]; + System.out.println(arr.length()); + } +} diff --git a/Java/Easy/91.java b/Java/Easy/91.java new file mode 100644 index 00000000..9237bea8 --- /dev/null +++ b/Java/Easy/91.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int[] arr = new int[3]{1, 2, 3}; + System.out.println(arr[0]); + } +} diff --git a/Java/Easy/92.java b/Java/Easy/92.java new file mode 100644 index 00000000..4dd45235 --- /dev/null +++ b/Java/Easy/92.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + double value = 10.5; + int result = value + 5; + System.out.println(result); + } +} diff --git a/Java/Easy/93.java b/Java/Easy/93.java new file mode 100644 index 00000000..2de7cdc8 --- /dev/null +++ b/Java/Easy/93.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String[] args) { + String text = null; + if (text.equals("Hello")) { + System.out.println("Text is Hello"); + } + } +} diff --git a/Java/Easy/94.java b/Java/Easy/94.java new file mode 100644 index 00000000..e10af0a1 --- /dev/null +++ b/Java/Easy/94.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + String result = 5 + 10; + System.out.println(result); + } +} diff --git a/Java/Easy/95.java b/Java/Easy/95.java new file mode 100644 index 00000000..619444e9 --- /dev/null +++ b/Java/Easy/95.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + char c = 'Hello'; + System.out.println(c); + } +} diff --git a/Java/Easy/96.java b/Java/Easy/96.java new file mode 100644 index 00000000..46e92b7e --- /dev/null +++ b/Java/Easy/96.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + int i = 10; + System.out.println(++i++); + } +} diff --git a/Java/Easy/97.java b/Java/Easy/97.java new file mode 100644 index 00000000..ace382ee --- /dev/null +++ b/Java/Easy/97.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + final int a = 5; + a = 10; + System.out.println(a); + } +} diff --git a/Java/Easy/98.java b/Java/Easy/98.java new file mode 100644 index 00000000..f67a3ee8 --- /dev/null +++ b/Java/Easy/98.java @@ -0,0 +1,7 @@ +class Main { + public static void main(String[] args) { + int[] arr = new int[5]; + arr.add(10); + System.out.println(arr[0]); + } +} diff --git a/Java/Easy/99.java b/Java/Easy/99.java new file mode 100644 index 00000000..6d3cd37a --- /dev/null +++ b/Java/Easy/99.java @@ -0,0 +1,6 @@ +class Main { + public static void main(String[] args) { + double x = 5 / 2; + System.out.println(x); + } +} diff --git a/Java/Easy/temp.txt b/Java/Easy/temp.txt new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/Java/Easy/temp.txt @@ -0,0 +1 @@ + diff --git a/Java/Hard/temp.txt b/Java/Hard/temp.txt new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/Java/Hard/temp.txt @@ -0,0 +1 @@ + diff --git a/Java/Medium/1.java b/Java/Medium/1.java new file mode 100644 index 00000000..aafae381 --- /dev/null +++ b/Java/Medium/1.java @@ -0,0 +1,22 @@ +// Question: Complete the binary search algorithm by ensuring it handles edge cases like empty arrays and target values outside the array. + +class Main { + public static int binarySearch(int[] arr, int target) { + int left = 0, right = arr.length - 1; + while (left <= right) { + int mid = (left + right) / 2; + if (arr[mid] == target) { + return mid; + } else if (arr[mid] < target) { + left = mid + 1; + } else { + right = mid - 1; + } + } + return -1; + } + public static void main(String[] args) { + int[] arr = {1, 2, 3, 4, 5}; + System.out.println(binarySearch(arr, 3)); + } +} diff --git a/Java/Medium/10.java b/Java/Medium/10.java new file mode 100644 index 00000000..5357ecef --- /dev/null +++ b/Java/Medium/10.java @@ -0,0 +1,29 @@ +// Question: Complete the Bubble Sort algorithm by ensuring it handles edge cases and sorts the array in ascending order. + +class Main { + public static void bubbleSort(int[] arr) { + int n = arr.length; + boolean swapped; + for (int i = 0; i < n - 1; i++) { + swapped = false; + for (int j = 0; j < n - i - 1; j++) { + if (arr[j] > arr[j + 1]) { + // Swap arr[j] and arr[j + 1] + int temp = arr[j]; + arr[j] = arr[j + 1]; + arr[j + 1] = temp; + swapped = true; + } + } + if (!swapped) break; + } + } + + public static void main(String[] args) { + int[] arr = {64, 34, 25, 12, 22, 11, 90}; + bubbleSort(arr); + for (int value : arr) { + System.out.print(value + " "); + } + } +} diff --git a/Java/Medium/11.java b/Java/Medium/11.java new file mode 100644 index 00000000..511fc8d3 --- /dev/null +++ b/Java/Medium/11.java @@ -0,0 +1,22 @@ +// Question: Complete the function to check if two strings are anagrams (contain the same characters in any order). + +import java.util.Arrays; + +class Main { + public static boolean areAnagrams(String str1, String str2) { + if (str1.length() != str2.length()) return false; + + char[] arr1 = str1.toCharArray(); + char[] arr2 = str2.toCharArray(); + Arrays.sort(arr1); + Arrays.sort(arr2); + + return Arrays.equals(arr1, arr2); + } + + public static void main(String[] args) { + String str1 = "listen"; + String str2 = "silent"; + System.out.println("Are anagrams: " + areAnagrams(str1, str2)); + } +} diff --git a/Java/Medium/12.java b/Java/Medium/12.java new file mode 100644 index 00000000..2ac05a52 --- /dev/null +++ b/Java/Medium/12.java @@ -0,0 +1,13 @@ +// Question: Complete the function to find the factorial of a number using recursion. + +class Main { + public static int factorial(int n) { + if (n == 0 || n == 1) return 1; + return n * factorial(n - 1); + } + + public static void main(String[] args) { + int n = 5; + System.out.println("Factorial of " + n + ": " + factorial(n)); + } +} diff --git a/Java/Medium/13.java b/Java/Medium/13.java new file mode 100644 index 00000000..fb6aee7f --- /dev/null +++ b/Java/Medium/13.java @@ -0,0 +1,20 @@ +// Question: Complete the function to find the longest common prefix in an array of strings. + +class Main { + public static String longestCommonPrefix(String[] strs) { + if (strs == null || strs.length == 0) return ""; + String prefix = strs[0]; + for (int i = 1; i < strs.length; i++) { + while (strs[i].indexOf(prefix) != 0) { + prefix = prefix.substring(0, prefix.length() - 1); + if (prefix.isEmpty()) return ""; + } + } + return prefix; + } + + public static void main(String[] args) { + String[] strs = {"flower", "flow", "flight"}; + System.out.println("Longest common prefix: " + longestCommonPrefix(strs)); + } +} diff --git a/Java/Medium/14.java b/Java/Medium/14.java new file mode 100644 index 00000000..c66e323c --- /dev/null +++ b/Java/Medium/14.java @@ -0,0 +1,23 @@ +// Question: Complete the insertion sort algorithm to sort an array in ascending order. + +class Main { + public static void insertionSort(int[] arr) { + for (int i = 1; i < arr.length; i++) { + int key = arr[i]; + int j = i - 1; + while (j >= 0 && arr[j] > key) { + arr[j + 1] = arr[j]; + j = j - 1; + } + arr[j + 1] = key; + } + } + + public static void main(String[] args) { + int[] arr = {12, 11, 13, 5, 6}; + insertionSort(arr); + for (int value : arr) { + System.out.print(value + " "); + } + } +} diff --git a/Java/Medium/15.java b/Java/Medium/15.java new file mode 100644 index 00000000..5e1c252b --- /dev/null +++ b/Java/Medium/15.java @@ -0,0 +1,23 @@ +// Question: Complete the function to reverse an array in place. + +class Main { + public static void reverseArray(int[] arr) { + int start = 0; + int end = arr.length - 1; + while (start < end) { + int temp = arr[start]; + arr[start] = arr[end]; + arr[end] = temp; + start++; + end--; + } + } + + public static void main(String[] args) { + int[] arr = {1, 2, 3, 4, 5}; + reverseArray(arr); + for (int value : arr) { + System.out.print(value + " "); + } + } +} diff --git a/Java/Medium/16.java b/Java/Medium/16.java new file mode 100644 index 00000000..dab340f5 --- /dev/null +++ b/Java/Medium/16.java @@ -0,0 +1,29 @@ +// Question: Complete the function to rotate an array by `k` steps to the right. + +class Main { + public static void rotateArray(int[] arr, int k) { + k %= arr.length; + reverse(arr, 0, arr.length - 1); + reverse(arr, 0, k - 1); + reverse(arr, k, arr.length - 1); + } + + private static void reverse(int[] arr, int start, int end) { + while (start < end) { + int temp = arr[start]; + arr[start] = arr[end]; + arr[end] = temp; + start++; + end--; + } + } + + public static void main(String[] args) { + int[] arr = {1, 2, 3, 4, 5, 6, 7}; + int k = 3; + rotateArray(arr, k); + for (int value : arr) { + System.out.print(value + " "); + } + } +} diff --git a/Java/Medium/17.java b/Java/Medium/17.java new file mode 100644 index 00000000..8a388946 --- /dev/null +++ b/Java/Medium/17.java @@ -0,0 +1,23 @@ +// Question: Complete the function to find the first non-repeated character in a string. + +import java.util.HashMap; + +class Main { + public static char firstNonRepeatedChar(String str) { + HashMap charCount = new HashMap<>(); + for (char c : str.toCharArray()) { + charCount.put(c, charCount.getOrDefault(c, 0) + 1); + } + for (char c : str.toCharArray()) { + if (charCount.get(c) == 1) { + return c; + } + } + return '\0'; // return null character if no non-repeated character found + } + + public static void main(String[] args) { + String str = "swiss"; + System.out.println("First non-repeated character: " + firstNonRepeatedChar(str)); + } +} diff --git a/Java/Medium/18.java b/Java/Medium/18.java new file mode 100644 index 00000000..93093a51 --- /dev/null +++ b/Java/Medium/18.java @@ -0,0 +1,13 @@ +// Question: Complete the function to check if one string is a rotation of another string. + +class Main { + public static boolean areRotations(String str1, String str2) { + return (str1.length() == str2.length()) && ((str1 + str1).contains(str2)); + } + + public static void main(String[] args) { + String str1 = "ABCD"; + String str2 = "CDAB"; + System.out.println("Are rotations: " + areRotations(str1, str2)); + } +} diff --git a/Java/Medium/19.java b/Java/Medium/19.java new file mode 100644 index 00000000..a7adef71 --- /dev/null +++ b/Java/Medium/19.java @@ -0,0 +1,13 @@ +// Question: Complete the function to check if a given number is a power of two. + +class Main { + public static boolean isPowerOfTwo(int n) { + if (n <= 0) return false; + return (n & (n - 1)) == 0; + } + + public static void main(String[] args) { + int n = 16; + System.out.println("Is power of two: " + isPowerOfTwo(n)); + } +} diff --git a/Java/Medium/2.java b/Java/Medium/2.java new file mode 100644 index 00000000..bf3572a5 --- /dev/null +++ b/Java/Medium/2.java @@ -0,0 +1,49 @@ +// Question: Complete the merge sort algorithm to handle the case of sorting arrays of any size correctly. + +class Main { + public static void mergeSort(int[] arr) { + if (arr.length < 2) { + return; + } + int mid = arr.length / 2; + int[] left = new int[mid]; + int[] right = new int[arr.length - mid]; + + // Copy data to left and right arrays + for (int i = 0; i < mid; i++) { + left[i] = arr[i]; + } + for (int i = mid; i < arr.length; i++) { + right[i - mid] = arr[i]; + } + + mergeSort(left); + mergeSort(right); + merge(arr, left, right); + } + + public static void merge(int[] arr, int[] left, int[] right) { + int i = 0, j = 0, k = 0; + while (i < left.length && j < right.length) { + if (left[i] <= right[j]) { + arr[k++] = left[i++]; + } else { + arr[k++] = right[j++]; + } + } + while (i < left.length) { + arr[k++] = left[i++]; + } + while (j < right.length) { + arr[k++] = right[j++]; + } + } + + public static void main(String[] args) { + int[] arr = {5, 2, 4, 7, 1, 3, 6, 8}; + mergeSort(arr); + for (int num : arr) { + System.out.print(num + " "); + } + } +} diff --git a/Java/Medium/20.java b/Java/Medium/20.java new file mode 100644 index 00000000..f6b8ed7e --- /dev/null +++ b/Java/Medium/20.java @@ -0,0 +1,17 @@ +// Question: Complete the function to find the missing number in an array of size `n-1` where elements are from 1 to `n`. + +class Main { + public static int findMissingNumber(int[] arr, int n) { + int sum = n * (n + 1) / 2; + int actualSum = 0; + for (int num : arr) { + actualSum += num; + } + return sum - actualSum; + } + + public static void main(String[] args) { + int[] arr = {1, 2, 4, 5, 6}; + System.out.println("Missing number: " + findMissingNumber(arr, 6)); + } +} diff --git a/Java/Medium/21.java b/Java/Medium/21.java new file mode 100644 index 00000000..6b06f318 --- /dev/null +++ b/Java/Medium/21.java @@ -0,0 +1,35 @@ +// Question: Complete the function to merge two sorted arrays into one sorted array. + +class Main { + public static int[] mergeArrays(int[] arr1, int[] arr2) { + int[] merged = new int[arr1.length + arr2.length]; + int i = 0, j = 0, k = 0; + + while (i < arr1.length && j < arr2.length) { + if (arr1[i] < arr2[j]) { + merged[k++] = arr1[i++]; + } else { + merged[k++] = arr2[j++]; + } + } + + while (i < arr1.length) { + merged[k++] = arr1[i++]; + } + + while (j < arr2.length) { + merged[k++] = arr2[j++]; + } + + return merged; + } + + public static void main(String[] args) { + int[] arr1 = {1, 3, 5}; + int[] arr2 = {2, 4, 6}; + int[] merged = mergeArrays(arr1, arr2); + for (int value : merged) { + System.out.print(value + " "); + } + } +} diff --git a/Java/Medium/22.java b/Java/Medium/22.java new file mode 100644 index 00000000..bf82ca5e --- /dev/null +++ b/Java/Medium/22.java @@ -0,0 +1,18 @@ +// Question: Complete the function to find the largest element in an array. + +class Main { + public static int findLargest(int[] arr) { + int largest = arr[0]; + for (int value : arr) { + if (value > largest) { + largest = value; + } + } + return largest; + } + + public static void main(String[] args) { + int[] arr = {10, 20, 30, 5, 1}; + System.out.println("Largest element: " + findLargest(arr)); + } +} diff --git a/Java/Medium/23.java b/Java/Medium/23.java new file mode 100644 index 00000000..26bbcb44 --- /dev/null +++ b/Java/Medium/23.java @@ -0,0 +1,27 @@ +// Question: Complete the function to find all prime factors of a number. + +class Main { + public static void primeFactors(int n) { + while (n % 2 == 0) { + System.out.print(2 + " "); + n /= 2; + } + + for (int i = 3; i <= Math.sqrt(n); i += 2) { + while (n % i == 0) { + System.out.print(i + " "); + n /= i; + } + } + + if (n > 2) { + System.out.print(n); + } + } + + public static void main(String[] args) { + int n = 315; + System.out.println("Prime factors of " + n + ": "); + primeFactors(n); + } +} diff --git a/Java/Medium/24.java b/Java/Medium/24.java new file mode 100644 index 00000000..c362147b --- /dev/null +++ b/Java/Medium/24.java @@ -0,0 +1,17 @@ +// Question: Complete the function to check if an array is sorted in ascending order. + +class Main { + public static boolean isSorted(int[] arr) { + for (int i = 0; i < arr.length - 1; i++) { + if (arr[i] > arr[i + 1]) { + return false; + } + } + return true; + } + + public static void main(String[] args) { + int[] arr = {1, 2, 3, 4, 5}; + System.out.println("Is array sorted: " + isSorted(arr)); + } +} diff --git a/Java/Medium/25.java b/Java/Medium/25.java new file mode 100644 index 00000000..faf7fbd2 --- /dev/null +++ b/Java/Medium/25.java @@ -0,0 +1,25 @@ +// Question: Complete the function to find and print all duplicate elements in an array. + +import java.util.HashSet; + +class Main { + public static void findDuplicates(int[] arr) { + HashSet seen = new HashSet<>(); + HashSet duplicates = new HashSet<>(); + + for (int num : arr) { + if (!seen.add(num)) { + duplicates.add(num); + } + } + + for (int duplicate : duplicates) { + System.out.println("Duplicate: " + duplicate); + } + } + + public static void main(String[] args) { + int[] arr = {1, 2, 3, 4, 5, 2, 3, 6}; + findDuplicates(arr); + } +} diff --git a/Java/Medium/26.java b/Java/Medium/26.java new file mode 100644 index 00000000..6fdda0aa --- /dev/null +++ b/Java/Medium/26.java @@ -0,0 +1,24 @@ +// Question: Complete the function to find the second largest element in an array. + +class Main { + public static int findSecondLargest(int[] arr) { + int largest = Integer.MIN_VALUE; + int secondLargest = Integer.MIN_VALUE; + + for (int value : arr) { + if (value > largest) { + secondLargest = largest; + largest = value; + } else if (value > secondLargest && value != largest) { + secondLargest = value; + } + } + + return secondLargest; + } + + public static void main(String[] args) { + int[] arr = {12, 35, 1, 10, 34, 1}; + System.out.println("Second largest element: " + findSecondLargest(arr)); + } +} diff --git a/Java/Medium/27.java b/Java/Medium/27.java new file mode 100644 index 00000000..250554f8 --- /dev/null +++ b/Java/Medium/27.java @@ -0,0 +1,24 @@ +// Question: Complete the function to find the intersection (common elements) of two arrays. + +import java.util.HashSet; + +class Main { + public static void findIntersection(int[] arr1, int[] arr2) { + HashSet set = new HashSet<>(); + for (int num : arr1) { + set.add(num); + } + + for (int num : arr2) { + if (set.contains(num)) { + System.out.println("Common element: " + num); + } + } + } + + public static void main(String[] args) { + int[] arr1 = {1, 2, 3, 4, 5}; + int[] arr2 = {4, 5, 6, 7, 8}; + findIntersection(arr1, arr2); + } +} diff --git a/Java/Medium/28.java b/Java/Medium/28.java new file mode 100644 index 00000000..0ea23cad --- /dev/null +++ b/Java/Medium/28.java @@ -0,0 +1,25 @@ +// Question: Complete the function to move all zeros to the end of an array without changing the order of non-zero elements. + +class Main { + public static void moveZerosToEnd(int[] arr) { + int nonZeroIndex = 0; + + for (int i = 0; i < arr.length; i++) { + if (arr[i] != 0) { + arr[nonZeroIndex++] = arr[i]; + } + } + + while (nonZeroIndex < arr.length) { + arr[nonZeroIndex++] = 0; + } + } + + public static void main(String[] args) { + int[] arr = {0, 1, 0, 3, 12}; + moveZerosToEnd(arr); + for (int value : arr) { + System.out.print(value + " "); + } + } +} diff --git a/Java/Medium/29.java b/Java/Medium/29.java new file mode 100644 index 00000000..2650fed9 --- /dev/null +++ b/Java/Medium/29.java @@ -0,0 +1,21 @@ +// Question: Complete the function to find the majority element in an array. A majority element appears more than n/2 times. + +import java.util.HashMap; + +class Main { + public static int findMajorityElement(int[] arr) { + HashMap countMap = new HashMap<>(); + for (int num : arr) { + countMap.put(num, countMap.getOrDefault(num, 0) + 1); + if (countMap.get(num) > arr.length / 2) { + return num; + } + } + return -1; // No majority element + } + + public static void main(String[] args) { + int[] arr = {2, 2, 1, 1, 1, 2, 2}; + System.out.println("Majority element: " + findMajorityElement(arr)); + } +} diff --git a/Java/Medium/3.java b/Java/Medium/3.java new file mode 100644 index 00000000..4a1de1d6 --- /dev/null +++ b/Java/Medium/3.java @@ -0,0 +1,15 @@ +// Question: Complete the Fibonacci sequence algorithm using recursion, but ensure it is optimized to handle large input values. + +class Main { + public static int fibonacci(int n) { + if (n <= 1) { + return n; + } + return fibonacci(n - 1) + fibonacci(n - 2); + } + + public static void main(String[] args) { + int n = 10; // Test with the 10th Fibonacci number + System.out.println("Fibonacci number " + n + ": " + fibonacci(n)); + } +} diff --git a/Java/Medium/30.java b/Java/Medium/30.java new file mode 100644 index 00000000..1a7c4b02 --- /dev/null +++ b/Java/Medium/30.java @@ -0,0 +1,22 @@ +// Question: Complete the function to find the Kth largest element in an unsorted array. + +import java.util.PriorityQueue; + +class Main { + public static int findKthLargest(int[] arr, int k) { + PriorityQueue minHeap = new PriorityQueue<>(); + for (int num : arr) { + minHeap.add(num); + if (minHeap.size() > k) { + minHeap.poll(); + } + } + return minHeap.peek(); + } + + public static void main(String[] args) { + int[] arr = {3, 2, 1, 5, 6, 4}; + int k = 2; + System.out.println("Kth largest element: " + findKthLargest(arr, k)); + } +} diff --git a/Java/Medium/31.java b/Java/Medium/31.java new file mode 100644 index 00000000..4b658f1c --- /dev/null +++ b/Java/Medium/31.java @@ -0,0 +1,32 @@ +// Question: Complete the function to check if a linked list has a cycle. + +class ListNode { + int val; + ListNode next; + ListNode(int x) { + val = x; + next = null; + } +} + +class Main { + public static boolean hasCycle(ListNode head) { + ListNode slow = head; + ListNode fast = head; + while (fast != null && fast.next != null) { + slow = slow.next; + fast = fast.next.next; + if (slow == fast) { + return true; + } + } + return false; + } + + public static void main(String[] args) { + ListNode head = new ListNode(1); + head.next = new ListNode(2); + head.next.next = head; // Creates a cycle + System.out.println("Has cycle: " + hasCycle(head)); + } +} diff --git a/Java/Medium/32.java b/Java/Medium/32.java new file mode 100644 index 00000000..67283893 --- /dev/null +++ b/Java/Medium/32.java @@ -0,0 +1,22 @@ +// Question: Complete the function to find and print all permutations of a string. + +class Main { + public static void permute(String str, String answer) { + if (str.length() == 0) { + System.out.println(answer); + return; + } + + for (int i = 0; i < str.length(); i++) { + char ch = str.charAt(i); + String leftSubstr = str.substring(0, i); + String rightSubstr = str.substring(i + 1); + permute(leftSubstr + rightSubstr, answer + ch); + } + } + + public static void main(String[] args) { + String str = "ABC"; + permute(str, ""); + } +} diff --git a/Java/Medium/33.java b/Java/Medium/33.java new file mode 100644 index 00000000..704ef3c6 --- /dev/null +++ b/Java/Medium/33.java @@ -0,0 +1,42 @@ +// Question: Complete the function to find the median of two sorted arrays. + +class Main { + public static double findMedianSortedArrays(int[] arr1, int[] arr2) { + int[] merged = mergeArrays(arr1, arr2); + int mid = merged.length / 2; + if (merged.length % 2 == 0) { + return (merged[mid - 1] + merged[mid]) / 2.0; + } else { + return merged[mid]; + } + } + + private static int[] mergeArrays(int[] arr1, int[] arr2) { + int[] merged = new int[arr1.length + arr2.length]; + int i = 0, j = 0, k = 0; + + while (i < arr1.length && j < arr2.length) { + if (arr1[i] < arr2[j]) { + merged[k++] = arr1[i++]; + } else { + merged[k++] = arr2[j++]; + } + } + + while (i < arr1.length) { + merged[k++] = arr1[i++]; + } + + while (j < arr2.length) { + merged[k++] = arr2[j++]; + } + + return merged; + } + + public static void main(String[] args) { + int[] arr1 = {1, 3}; + int[] arr2 = {2}; + System.out.println("Median: " + findMedianSortedArrays(arr1, arr2)); + } +} diff --git a/Java/Medium/34.java b/Java/Medium/34.java new file mode 100644 index 00000000..e21c629a --- /dev/null +++ b/Java/Medium/34.java @@ -0,0 +1,31 @@ +// Question: Complete the function to find the longest palindromic substring in a given string. + +class Main { + public static String longestPalindrome(String s) { + if (s == null || s.length() < 1) return ""; + int start = 0, end = 0; + for (int i = 0; i < s.length(); i++) { + int len1 = expandAroundCenter(s, i, i); + int len2 = expandAroundCenter(s, i, i + 1); + int len = Math.max(len1, len2); + if (len > end - start) { + start = i - (len - 1) / 2; + end = i + len / 2; + } + } + return s.substring(start, end + 1); + } + + private static int expandAroundCenter(String s, int left, int right) { + while (left >= 0 && right < s.length() && s.charAt(left) == s.charAt(right)) { + left--; + right++; + } + return right - left - 1; + } + + public static void main(String[] args) { + String s = "babad"; + System.out.println("Longest palindromic substring: " + longestPalindrome(s)); + } +} diff --git a/Java/Medium/35.java b/Java/Medium/35.java new file mode 100644 index 00000000..0b898d3c --- /dev/null +++ b/Java/Medium/35.java @@ -0,0 +1,29 @@ +// Question: Complete the function to find and print all subsets of a given set of integers. + +import java.util.ArrayList; +import java.util.List; + +class Main { + public static List> subsets(int[] nums) { + List> result = new ArrayList<>(); + generateSubsets(0, nums, new ArrayList<>(), result); + return result; + } + + private static void generateSubsets(int index, int[] nums, List current, List> result) { + result.add(new ArrayList<>(current)); + for (int i = index; i < nums.length; i++) { + current.add(nums[i]); + generateSubsets(i + 1, nums, current, result); + current.remove(current.size() - 1); + } + } + + public static void main(String[] args) { + int[] nums = {1, 2, 3}; + List> subsets = subsets(nums); + for (List subset : subsets) { + System.out.println(subset); + } + } +} diff --git a/Java/Medium/36.java b/Java/Medium/36.java new file mode 100644 index 00000000..a056e175 --- /dev/null +++ b/Java/Medium/36.java @@ -0,0 +1,32 @@ +// Question: Complete the function to find the first missing positive integer in an unsorted array. + +class Main { + public static int firstMissingPositive(int[] nums) { + int n = nums.length; + + for (int i = 0; i < n; i++) { + while (nums[i] > 0 && nums[i] <= n && nums[nums[i] - 1] != nums[i]) { + swap(nums, i, nums[i] - 1); + } + } + + for (int i = 0; i < n; i++) { + if (nums[i] != i + 1) { + return i + 1; + } + } + + return n + 1; + } + + private static void swap(int[] nums, int i, int j) { + int temp = nums[i]; + nums[i] = nums[j]; + nums[j] = temp; + } + + public static void main(String[] args) { + int[] nums = {3, 4, -1, 1}; + System.out.println("First missing positive: " + firstMissingPositive(nums)); + } +} diff --git a/Java/Medium/37.java b/Java/Medium/37.java new file mode 100644 index 00000000..ea30338c --- /dev/null +++ b/Java/Medium/37.java @@ -0,0 +1,40 @@ +// Question: Complete the function to find all paths from the top-left corner to the bottom-right corner of a maze. + +import java.util.ArrayList; +import java.util.List; + +class Main { + public static List findAllPaths(int[][] maze, int x, int y, String path) { + List result = new ArrayList<>(); + if (x == maze.length - 1 && y == maze[0].length - 1) { + result.add(path); + return result; + } + + // Move down + if (x + 1 < maze.length && maze[x + 1][y] == 1) { + result.addAll(findAllPaths(maze, x + 1, y, path + "D")); + } + + // Move right + if (y + 1 < maze[0].length && maze[x][y + 1] == 1) { + result.addAll(findAllPaths(maze, x, y + 1, path + "R")); + } + + return result; + } + + public static void main(String[] args) { + int[][] maze = { + {1, 0, 0, 0}, + {1, 1, 0, 1}, + {0, 1, 0, 0}, + {1, 1, 1, 1} + }; + + List paths = findAllPaths(maze, 0, 0, ""); + for (String path : paths) { + System.out.println(path); + } + } +} diff --git a/Java/Medium/38.java b/Java/Medium/38.java new file mode 100644 index 00000000..ce81d1f9 --- /dev/null +++ b/Java/Medium/38.java @@ -0,0 +1,37 @@ +// Question: Complete the function to find the diameter (longest path) of a binary tree. + +class TreeNode { + int val; + TreeNode left; + TreeNode right; + + TreeNode(int x) { + val = x; + } +} + +class Main { + public static int diameterOfBinaryTree(TreeNode root) { + int[] diameter = new int[1]; + height(root, diameter); + return diameter[0]; + } + + private static int height(TreeNode node, int[] diameter) { + if (node == null) return 0; + int leftHeight = height(node.left, diameter); + int rightHeight = height(node.right, diameter); + diameter[0] = Math.max(diameter[0], leftHeight + rightHeight); + return 1 + Math.max(leftHeight, rightHeight); + } + + public static void main(String[] args) { + TreeNode root = new TreeNode(1); + root.left = new TreeNode(2); + root.right = new TreeNode(3); + root.left.left = new TreeNode(4); + root.left.right = new TreeNode(5); + + System.out.println("Diameter of the tree: " + diameterOfBinaryTree(root)); + } +} diff --git a/Java/Medium/39.java b/Java/Medium/39.java new file mode 100644 index 00000000..fbd202d7 --- /dev/null +++ b/Java/Medium/39.java @@ -0,0 +1,40 @@ +// Question: Complete the function to find the lowest common ancestor (LCA) of two nodes in a binary search tree. + +class TreeNode { + int val; + TreeNode left; + TreeNode right; + + TreeNode(int x) { + val = x; + } +} + +class Main { + public static TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { + if (root == null) return null; + + if (p.val < root.val && q.val < root.val) { + return lowestCommonAncestor(root.left, p, q); + } else if (p.val > root.val && q.val > root.val) { + return lowestCommonAncestor(root.right, p, q); + } else { + return root; + } + } + + public static void main(String[] args) { + TreeNode root = new TreeNode(6); + root.left = new TreeNode(2); + root.right = new TreeNode(8); + root.left.left = new TreeNode(0); + root.left.right = new TreeNode(4); + root.right.left = new TreeNode(7); + root.right.right = new TreeNode(9); + + TreeNode p = root.left; // Node with value 2 + TreeNode q = root.right; // Node with value 8 + + System.out.println("Lowest common ancestor: " + lowestCommonAncestor(root, p, q).val); + } +} diff --git a/Java/Medium/4.java b/Java/Medium/4.java new file mode 100644 index 00000000..5bdf498d --- /dev/null +++ b/Java/Medium/4.java @@ -0,0 +1,17 @@ +// Question: Complete the code to find the maximum sum of a contiguous subarray within a one-dimensional array of numbers using Kadane’s Algorithm. + +class Main { + public static int maxSubArray(int[] arr) { + int maxSoFar = arr[0], maxEndingHere = arr[0]; + for (int i = 1; i < arr.length; i++) { + maxEndingHere = Math.max(arr[i], maxEndingHere + arr[i]); + maxSoFar = Math.max(maxSoFar, maxEndingHere); + } + return maxSoFar; + } + + public static void main(String[] args) { + int[] arr = {-2, 1, -3, 4, -1, 2, 1, -5, 4}; + System.out.println("Maximum subarray sum: " + maxSubArray(arr)); + } +} diff --git a/Java/Medium/40.java b/Java/Medium/40.java new file mode 100644 index 00000000..52b82484 --- /dev/null +++ b/Java/Medium/40.java @@ -0,0 +1,28 @@ +// Question: Complete the function to find the maximum depth (height) of a binary tree. + +class TreeNode { + int val; + TreeNode left; + TreeNode right; + + TreeNode(int x) { + val = x; + } +} + +class Main { + public static int maxDepth(TreeNode root) { + if (root == null) return 0; + return 1 + Math.max(maxDepth(root.left), maxDepth(root.right)); + } + + public static void main(String[] args) { + TreeNode root = new TreeNode(1); + root.left = new TreeNode(2); + root.right = new TreeNode(3); + root.left.left = new TreeNode(4); + root.left.right = new TreeNode(5); + + System.out.println("Maximum depth of the tree: " + maxDepth(root)); + } +} diff --git a/Java/Medium/41.java b/Java/Medium/41.java new file mode 100644 index 00000000..78102891 --- /dev/null +++ b/Java/Medium/41.java @@ -0,0 +1,29 @@ +// Question: Complete the function to perform inorder traversal of a binary tree. + +class TreeNode { + int val; + TreeNode left; + TreeNode right; + + TreeNode(int x) { + val = x; + } +} + +class Main { + public static void inorderTraversal(TreeNode root) { + if (root == null) return; + inorderTraversal(root.left); + System.out.print(root.val + " "); + inorderTraversal(root.right); + } + + public static void main(String[] args) { + TreeNode root = new TreeNode(1); + root.right = new TreeNode(2); + root.right.left = new TreeNode(3); + + System.out.print("Inorder traversal: "); + inorderTraversal(root); + } +} diff --git a/Java/Medium/42.java b/Java/Medium/42.java new file mode 100644 index 00000000..2b7aadcb --- /dev/null +++ b/Java/Medium/42.java @@ -0,0 +1,36 @@ +// Question: Complete the function to perform breadth-first search (BFS) on a graph. + +import java.util.LinkedList; +import java.util.Queue; + +class Main { + public static void bfs(int[][] graph, int start) { + boolean[] visited = new boolean[graph.length]; + Queue queue = new LinkedList<>(); + queue.add(start); + visited[start] = true; + + while (!queue.isEmpty()) { + int node = queue.poll(); + System.out.print(node + " "); + + for (int i = 0; i < graph[node].length; i++) { + if (graph[node][i] == 1 && !visited[i]) { + queue.add(i); + visited[i] = true; + } + } + } + } + + public static void main(String[] args) { + int[][] graph = { + {0, 1, 1, 0}, + {1, 0, 1, 1}, + {1, 1, 0, 1}, + {0, 1, 1, 0} + }; + System.out.print("BFS: "); + bfs(graph, 0); + } +} diff --git a/Java/Medium/43.java b/Java/Medium/43.java new file mode 100644 index 00000000..f4c8419a --- /dev/null +++ b/Java/Medium/43.java @@ -0,0 +1,26 @@ +// Question: Complete the function to perform depth-first search (DFS) on a graph. + +class Main { + public static void dfs(int[][] graph, int start, boolean[] visited) { + visited[start] = true; + System.out.print(start + " "); + + for (int i = 0; i < graph[start].length; i++) { + if (graph[start][i] == 1 && !visited[i]) { + dfs(graph, i, visited); + } + } + } + + public static void main(String[] args) { + int[][] graph = { + {0, 1, 1, 0}, + {1, 0, 1, 1}, + {1, 1, 0, 1}, + {0, 1, 1, 0} + }; + boolean[] visited = new boolean[graph.length]; + System.out.print("DFS: "); + dfs(graph, 0, visited); + } +} diff --git a/Java/Medium/44.java b/Java/Medium/44.java new file mode 100644 index 00000000..6cbf23e4 --- /dev/null +++ b/Java/Medium/44.java @@ -0,0 +1,19 @@ +// Question: Complete the function to find the Nth Fibonacci number using dynamic programming. + +class Main { + public static int fibonacciDP(int n) { + if (n <= 1) return n; + int[] fib = new int[n + 1]; + fib[0] = 0; + fib[1] = 1; + for (int i = 2; i <= n; i++) { + fib[i] = fib[i - 1] + fib[i - 2]; + } + return fib[n]; + } + + public static void main(String[] args) { + int n = 10; + System.out.println("Fibonacci number " + n + ": " + fibonacciDP(n)); + } +} diff --git a/Java/Medium/45.java b/Java/Medium/45.java new file mode 100644 index 00000000..34472605 --- /dev/null +++ b/Java/Medium/45.java @@ -0,0 +1,34 @@ +// Question: Complete the function to check if a binary tree is symmetric (a mirror of itself). + +class TreeNode { + int val; + TreeNode left, right; + TreeNode(int x) { + val = x; + } +} + +class Main { + public static boolean isSymmetric(TreeNode root) { + if (root == null) return true; + return isMirror(root.left, root.right); + } + + private static boolean isMirror(TreeNode t1, TreeNode t2) { + if (t1 == null && t2 == null) return true; + if (t1 == null || t2 == null) return false; + return (t1.val == t2.val) && isMirror(t1.left, t2.right) && isMirror(t1.right, t2.left); + } + + public static void main(String[] args) { + TreeNode root = new TreeNode(1); + root.left = new TreeNode(2); + root.right = new TreeNode(2); + root.left.left = new TreeNode(3); + root.left.right = new TreeNode(4); + root.right.left = new TreeNode(4); + root.right.right = new TreeNode(3); + + System.out.println("Is symmetric: " + isSymmetric(root)); + } +} diff --git a/Java/Medium/46.java b/Java/Medium/46.java new file mode 100644 index 00000000..68a2722e --- /dev/null +++ b/Java/Medium/46.java @@ -0,0 +1,36 @@ +// Question: Complete the function to count the number of islands in a 2D grid (using DFS). + +class Main { + public static int numIslands(char[][] grid) { + if (grid == null || grid.length == 0) return 0; + int numIslands = 0; + for (int i = 0; i < grid.length; i++) { + for (int j = 0; j < grid[0].length; j++) { + if (grid[i][j] == '1') { + numIslands += dfs(grid, i, j); + } + } + } + return numIslands; + } + + private static int dfs(char[][] grid, int i, int j) { + if (i < 0 || i >= grid.length || j < 0 || j >= grid[0].length || grid[i][j] == '0') return 0; + grid[i][j] = '0'; // Mark visited + dfs(grid, i - 1, j); + dfs(grid, i + 1, j); + dfs(grid, i, j - 1); + dfs(grid, i, j + 1); + return 1; + } + + public static void main(String[] args) { + char[][] grid = { + {'1', '1', '0', '0', '0'}, + {'1', '1', '0', '0', '0'}, + {'0', '0', '1', '0', '0'}, + {'0', '0', '0', '1', '1'} + }; + System.out.println("Number of islands: " + numIslands(grid)); + } +} diff --git a/Java/Medium/47.java b/Java/Medium/47.java new file mode 100644 index 00000000..0a27a665 --- /dev/null +++ b/Java/Medium/47.java @@ -0,0 +1,32 @@ +// Question: Complete the function to find the minimum path sum from the top-left corner to the bottom-right corner of a grid. + +class Main { + public static int minPathSum(int[][] grid) { + int rows = grid.length; + int cols = grid[0].length; + + for (int i = 1; i < rows; i++) { + grid[i][0] += grid[i - 1][0]; + } + for (int j = 1; j < cols; j++) { + grid[0][j] += grid[0][j - 1]; + } + + for (int i = 1; i < rows; i++) { + for (int j = 1; j < cols; j++) { + grid[i][j] += Math.min(grid[i - 1][j], grid[i][j - 1]); + } + } + + return grid[rows - 1][cols - 1]; + } + + public static void main(String[] args) { + int[][] grid = { + {1, 3, 1}, + {1, 5, 1}, + {4, 2, 1} + }; + System.out.println("Minimum path sum: " + minPathSum(grid)); + } +} diff --git a/Java/Medium/48.java b/Java/Medium/48.java new file mode 100644 index 00000000..5e24118e --- /dev/null +++ b/Java/Medium/48.java @@ -0,0 +1,26 @@ +// Question: Complete the function to solve the 0/1 Knapsack problem using dynamic programming. + +class Main { + public static int knapsack(int[] weights, int[] values, int capacity) { + int n = weights.length; + int[][] dp = new int[n + 1][capacity + 1]; + + for (int i = 1; i <= n; i++) { + for (int w = 0; w <= capacity; w++) { + if (weights[i - 1] <= w) { + dp[i][w] = Math.max(dp[i - 1][w], values[i - 1] + dp[i - 1][w - weights[i - 1]]); + } else { + dp[i][w] = dp[i - 1][w]; + } + } + } + return dp[n][capacity]; + } + + public static void main(String[] args) { + int[] weights = {1, 3, 4, 5}; + int[] values = {1, 4, 5, 7}; + int capacity = 7; + System.out.println("Maximum value: " + knapsack(weights, values, capacity)); + } +} diff --git a/Java/Medium/49.java b/Java/Medium/49.java new file mode 100644 index 00000000..657f1063 --- /dev/null +++ b/Java/Medium/49.java @@ -0,0 +1,33 @@ +// Question: Complete the function to convert a binary tree into its mirror. + +class TreeNode { + int val; + TreeNode left, right; + TreeNode(int x) { + val = x; + } +} + +class Main { + public static TreeNode mirror(TreeNode root) { + if (root == null) return null; + TreeNode temp = root.left; + root.left = root.right; + root.right = temp; + + mirror(root.left); + mirror(root.right); + return root; + } + + public static void main(String[] args) { + TreeNode root = new TreeNode(1); + root.left = new TreeNode(2); + root.right = new TreeNode(3); + root.left.left = new TreeNode(4); + root.left.right = new TreeNode(5); + + root = mirror(root); + System.out.println("Root of mirrored tree: " + root.val); + } +} diff --git a/Java/Medium/5.java b/Java/Medium/5.java new file mode 100644 index 00000000..bdf6a929 --- /dev/null +++ b/Java/Medium/5.java @@ -0,0 +1,28 @@ +// Question: Complete the code to find and print all prime numbers less than or equal to a given number N. + +class Main { + public static boolean isPrime(int n) { + if (n <= 1) { + return false; + } + for (int i = 2; i * i <= n; i++) { + if (n % i == 0) { + return false; + } + } + return true; + } + + public static void printPrimes(int n) { + for (int i = 2; i <= n; i++) { + if (isPrime(i)) { + System.out.print(i + " "); + } + } + } + + public static void main(String[] args) { + int n = 30; // Find primes up to 30 + printPrimes(n); + } +} diff --git a/Java/Medium/50.java b/Java/Medium/50.java new file mode 100644 index 00000000..c508d501 --- /dev/null +++ b/Java/Medium/50.java @@ -0,0 +1,32 @@ +// Question: Complete the function to find the longest increasing subsequence in an array. + +import java.util.Arrays; + +class Main { + public static int lengthOfLIS(int[] nums) { + if (nums.length == 0) return 0; + + int[] dp = new int[nums.length]; + Arrays.fill(dp, 1); + + for (int i = 1; i < nums.length; i++) { + for (int j = 0; j < i; j++) { + if (nums[i] > nums[j]) { + dp[i] = Math.max(dp[i], dp[j] + 1); + } + } + } + + int maxLength = 0; + for (int length : dp) { + maxLength = Math.max(maxLength, length); + } + + return maxLength; + } + + public static void main(String[] args) { + int[] nums = {10, 9, 2, 5, 3, 7, 101, 18}; + System.out.println("Length of LIS: " + lengthOfLIS(nums)); + } +} diff --git a/Java/Medium/6.java b/Java/Medium/6.java new file mode 100644 index 00000000..5b87361e --- /dev/null +++ b/Java/Medium/6.java @@ -0,0 +1,20 @@ +// Question: Complete the function to check if a given string is a palindrome (the same forwards and backwards). + +class Main { + public static boolean isPalindrome(String str) { + int left = 0, right = str.length() - 1; + while (left < right) { + if (str.charAt(left) != str.charAt(right)) { + return false; + } + left++; + right--; + } + return true; + } + + public static void main(String[] args) { + String str = "racecar"; + System.out.println("Is palindrome: " + isPalindrome(str)); + } +} diff --git a/Java/Medium/7.java b/Java/Medium/7.java new file mode 100644 index 00000000..9e283f19 --- /dev/null +++ b/Java/Medium/7.java @@ -0,0 +1,17 @@ +// Question: Complete the function to calculate the greatest common divisor (GCD) of two numbers using Euclid's algorithm. + +class Main { + public static int gcd(int a, int b) { + while (b != 0) { + int temp = b; + b = a % b; + a = temp; + } + return a; + } + + public static void main(String[] args) { + int a = 56, b = 98; + System.out.println("GCD: " + gcd(a, b)); + } +} diff --git a/Java/Medium/8.java b/Java/Medium/8.java new file mode 100644 index 00000000..00beecb3 --- /dev/null +++ b/Java/Medium/8.java @@ -0,0 +1,36 @@ +// Question: Complete the function to reverse a singly linked list. + +class ListNode { + int val; + ListNode next; + ListNode(int x) { + val = x; + next = null; + } +} + +class Main { + public static ListNode reverseList(ListNode head) { + ListNode prev = null; + ListNode current = head; + while (current != null) { + ListNode nextNode = current.next; + current.next = prev; + prev = current; + current = nextNode; + } + return prev; + } + + public static void main(String[] args) { + ListNode head = new ListNode(1); + head.next = new ListNode(2); + head.next.next = new ListNode(3); + + head = reverseList(head); + while (head != null) { + System.out.print(head.val + " "); + head = head.next; + } + } +} diff --git a/Java/Medium/9.java b/Java/Medium/9.java new file mode 100644 index 00000000..ceaeb64e --- /dev/null +++ b/Java/Medium/9.java @@ -0,0 +1,57 @@ +// Question: Complete the function to count inversions in an array. An inversion is when a pair of elements are out of order. + +class Main { + public static int countInversions(int[] arr) { + return mergeSortAndCount(arr, 0, arr.length - 1); + } + + private static int mergeSortAndCount(int[] arr, int left, int right) { + int count = 0; + if (left < right) { + int mid = (left + right) / 2; + + count += mergeSortAndCount(arr, left, mid); + count += mergeSortAndCount(arr, mid + 1, right); + count += mergeAndCount(arr, left, mid, right); + } + return count; + } + + private static int mergeAndCount(int[] arr, int left, int mid, int right) { + int[] leftArr = new int[mid - left + 1]; + int[] rightArr = new int[right - mid]; + + for (int i = 0; i < leftArr.length; i++) { + leftArr[i] = arr[left + i]; + } + for (int i = 0; i < rightArr.length; i++) { + rightArr[i] = arr[mid + 1 + i]; + } + + int i = 0, j = 0, k = left, swaps = 0; + + while (i < leftArr.length && j < rightArr.length) { + if (leftArr[i] <= rightArr[j]) { + arr[k++] = leftArr[i++]; + } else { + arr[k++] = rightArr[j++]; + swaps += (mid + 1) - (left + i); + } + } + + while (i < leftArr.length) { + arr[k++] = leftArr[i++]; + } + + while (j < rightArr.length) { + arr[k++] = rightArr[j++]; + } + + return swaps; + } + + public static void main(String[] args) { + int[] arr = {1, 20, 6, 4, 5}; + System.out.println("Number of inversions: " + countInversions(arr)); + } +} diff --git a/Java/Medium/temp.txt b/Java/Medium/temp.txt new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/Java/Medium/temp.txt @@ -0,0 +1 @@ + diff --git a/Java/j1.java b/Java/j1.java deleted file mode 100644 index 24eb8e4b..00000000 --- a/Java/j1.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = 5 - System.out.println(x); - } -} diff --git a/Java/j10.java b/Java/j10.java deleted file mode 100644 index 0669f78b..00000000 --- a/Java/j10.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - String name = "John"; - char letter = name.charAt(5); - System.out.println(letter); - } -} diff --git a/Java/j100.java b/Java/j100.java deleted file mode 100644 index 47f78cd4..00000000 --- a/Java/j100.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String[] names = {"Alice", "Bob"}; - System.out.println(names.get(0)); - } -} diff --git a/Java/j101.java b/Java/j101.java deleted file mode 100644 index 04d37169..00000000 --- a/Java/j101.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = Math.abs(); - System.out.println(x); - } -} diff --git a/Java/j102.java b/Java/j102.java deleted file mode 100644 index 55dba6bb..00000000 --- a/Java/j102.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - for (int i = 0; i < 5) { - System.out.println(i); - } - } -} diff --git a/Java/j103.java b/Java/j103.java deleted file mode 100644 index 7541cfb5..00000000 --- a/Java/j103.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - List numbers = new ArrayList<>(); - numbers.add(10); - System.out.println(numbers.get(0)); - } -} diff --git a/Java/j104.java b/Java/j104.java deleted file mode 100644 index 91fcf538..00000000 --- a/Java/j104.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String[] items = {"apple", "banana"}; - System.out.println(items[2]); - } -} diff --git a/Java/j105.java b/Java/j105.java deleted file mode 100644 index 6cd8dfcd..00000000 --- a/Java/j105.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String text = "java"; - System.out.println(text.ToUpperCase()); - } -} diff --git a/Java/j106.java b/Java/j106.java deleted file mode 100644 index a64ab5fd..00000000 --- a/Java/j106.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x; - System.out.println(x); - } -} diff --git a/Java/j107.java b/Java/j107.java deleted file mode 100644 index 2128aa29..00000000 --- a/Java/j107.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] numbers = {1, 2, 3}; - System.out.println(numbers.toString()); - } -} diff --git a/Java/j108.java b/Java/j108.java deleted file mode 100644 index afb85272..00000000 --- a/Java/j108.java +++ /dev/null @@ -1,5 +0,0 @@ -public class Main { - public static void main(String[] args) { - System.out.println(5. / 0); - } -} diff --git a/Java/j109.java b/Java/j109.java deleted file mode 100644 index d5df4b28..00000000 --- a/Java/j109.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] arr = new int[5]; - for (int i : arr) { - arr[i] = i * 2; - } - } -} diff --git a/Java/j11.java b/Java/j11.java deleted file mode 100644 index 402ae089..00000000 --- a/Java/j11.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - boolean isValid = True; - System.out.println(isValid); - } -} diff --git a/Java/j110.java b/Java/j110.java deleted file mode 100644 index 73544d10..00000000 --- a/Java/j110.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - double x = Math.pow(2); - System.out.println(x); - } -} diff --git a/Java/j111.java b/Java/j111.java deleted file mode 100644 index 7c4d3274..00000000 --- a/Java/j111.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] arr = new int[5]; - for (int i = 0; i <= arr.length; i++) { - arr[i] = i; - } - } -} diff --git a/Java/j112.java b/Java/j112.java deleted file mode 100644 index 52ca32df..00000000 --- a/Java/j112.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] arr = new int[3]; - arr.add(5); - } -} diff --git a/Java/j113.java b/Java/j113.java deleted file mode 100644 index a81fbba9..00000000 --- a/Java/j113.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - String s = "Java"; - s.toLowerCase; - System.out.println(s); - } -} diff --git a/Java/j114.java b/Java/j114.java deleted file mode 100644 index 465a2dc8..00000000 --- a/Java/j114.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] numbers = {1, 2, 3}; - System.out.println(numbers(0)); - } -} diff --git a/Java/j115.java b/Java/j115.java deleted file mode 100644 index b895ac41..00000000 --- a/Java/j115.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] arr = new int[5]; - System.out.println(arr.length()); - } -} diff --git a/Java/j116.java b/Java/j116.java deleted file mode 100644 index d0983e18..00000000 --- a/Java/j116.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - String s = "apple"; - s.charAt(5); - System.out.println(s); - } -} diff --git a/Java/j117.java b/Java/j117.java deleted file mode 100644 index ff52a4d9..00000000 --- a/Java/j117.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String str = 100; - System.out.println(str); - } -} diff --git a/Java/j118.java b/Java/j118.java deleted file mode 100644 index effdaa79..00000000 --- a/Java/j118.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] numbers = new int[-10]; - System.out.println(numbers.length); - } -} diff --git a/Java/j119.java b/Java/j119.java deleted file mode 100644 index 110543be..00000000 --- a/Java/j119.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - List list = new ArrayList<>(); - list.add("Alice"); - System.out.println(list[0]); - } -} diff --git a/Java/j12.java b/Java/j12.java deleted file mode 100644 index 0ac2316e..00000000 --- a/Java/j12.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int number = "50"; - System.out.println(number); - } -} diff --git a/Java/j120.java b/Java/j120.java deleted file mode 100644 index 02893275..00000000 --- a/Java/j120.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - List names = new ArrayList<>(); - names.add("John", "Doe"); - System.out.println(names); - } -} diff --git a/Java/j121.java b/Java/j121.java deleted file mode 100644 index 603148d5..00000000 --- a/Java/j121.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 5; - int result = Math.pow(a, 2); - System.out.println(result); - } -} diff --git a/Java/j122.java b/Java/j122.java deleted file mode 100644 index 393a2af9..00000000 --- a/Java/j122.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = 5; - if (x > 10) - System.out.println("x is greater than 10"); - System.out.println("This will always print"); - } -} diff --git a/Java/j123.java b/Java/j123.java deleted file mode 100644 index 715095e9..00000000 --- a/Java/j123.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - int num = 0; - do { - System.out.println(num); - } while num < 5; - } -} diff --git a/Java/j124.java b/Java/j124.java deleted file mode 100644 index b681b8b0..00000000 --- a/Java/j124.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 5; - String s = (String) a; - System.out.println(s); - } -} diff --git a/Java/j125.java b/Java/j125.java deleted file mode 100644 index a57cb017..00000000 --- a/Java/j125.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - String str = "hello"; - str.concat(" world"); - System.out.println(str); - } -} diff --git a/Java/j126.java b/Java/j126.java deleted file mode 100644 index 3f771e9d..00000000 --- a/Java/j126.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = 5; - System.out.println("Square of x is: " + Math.square(x)); - } -} diff --git a/Java/j127.java b/Java/j127.java deleted file mode 100644 index 38706658..00000000 --- a/Java/j127.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String[] colors = {"red", "green", "blue"}; - System.out.println(colors[3]); - } -} diff --git a/Java/j128.java b/Java/j128.java deleted file mode 100644 index f34b0230..00000000 --- a/Java/j128.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - String name = "Alice"; - char letter = name[0]; - System.out.println(letter); - } -} diff --git a/Java/j129.java b/Java/j129.java deleted file mode 100644 index 00c931f9..00000000 --- a/Java/j129.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - int i = 0; - for (; i < 5) { - System.out.println(i); - } - } -} diff --git a/Java/j13.java b/Java/j13.java deleted file mode 100644 index bb6808a2..00000000 --- a/Java/j13.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 10; - Integer b = null; - System.out.println(a.equals(b)); - } -} diff --git a/Java/j130.java b/Java/j130.java deleted file mode 100644 index 036f27ce..00000000 --- a/Java/j130.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 5; - String b = (String) a; - System.out.println(b); - } -} diff --git a/Java/j131.java b/Java/j131.java deleted file mode 100644 index 071f63be..00000000 --- a/Java/j131.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - for (int i = 0; i < 5) { - System.out.println(i); - } - System.out.println(i); - } -} diff --git a/Java/j132.java b/Java/j132.java deleted file mode 100644 index 421c0da7..00000000 --- a/Java/j132.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - String s = "java"; - s.replace('a', "o"); - System.out.println(s); - } -} diff --git a/Java/j133.java b/Java/j133.java deleted file mode 100644 index 3c0f32ab..00000000 --- a/Java/j133.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 5; - System.out.println(a++); - } -} diff --git a/Java/j134.java b/Java/j134.java deleted file mode 100644 index 8006c3d4..00000000 --- a/Java/j134.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - List numbers = new ArrayList<>(); - numbers.add(5); - System.out.println(numbers.get(0)); - } -} diff --git a/Java/j135.java b/Java/j135.java deleted file mode 100644 index 82ccb17d..00000000 --- a/Java/j135.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String message = null; - System.out.println(message.length()); - } -} diff --git a/Java/j136.java b/Java/j136.java deleted file mode 100644 index c2d6467a..00000000 --- a/Java/j136.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - char c = 'Hello'; - System.out.println(c); - } -} diff --git a/Java/j137.java b/Java/j137.java deleted file mode 100644 index c57f8f3f..00000000 --- a/Java/j137.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 5; - String s = Integer.toString(a); - System.out.println(s * 2); - } -} diff --git a/Java/j138.java b/Java/j138.java deleted file mode 100644 index 332f8a01..00000000 --- a/Java/j138.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - double x = Math.abs(); - System.out.println(x); - } -} diff --git a/Java/j139.java b/Java/j139.java deleted file mode 100644 index b6be7c26..00000000 --- a/Java/j139.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String[] arr = {"apple", "banana", "orange"}; - System.out.println(arr.size()); - } -} diff --git a/Java/j14.java b/Java/j14.java deleted file mode 100644 index 74f374ce..00000000 --- a/Java/j14.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - char ch = 'abc'; - System.out.println(ch); - } -} diff --git a/Java/j140.java b/Java/j140.java deleted file mode 100644 index 8efcdd08..00000000 --- a/Java/j140.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = 5 / 0; - System.out.println(x); - } -} diff --git a/Java/j141.java b/Java/j141.java deleted file mode 100644 index 4992a0f0..00000000 --- a/Java/j141.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 10; - String s = (String) a; - System.out.println(s); - } -} diff --git a/Java/j142.java b/Java/j142.java deleted file mode 100644 index 6a188364..00000000 --- a/Java/j142.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 10; - Integer b = null; - int result = a + b; - System.out.println(result); - } -} diff --git a/Java/j143.java b/Java/j143.java deleted file mode 100644 index 465a2dc8..00000000 --- a/Java/j143.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] numbers = {1, 2, 3}; - System.out.println(numbers(0)); - } -} diff --git a/Java/j144.java b/Java/j144.java deleted file mode 100644 index c8310967..00000000 --- a/Java/j144.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 10; - double result = a / 0; - System.out.println(result); - } -} diff --git a/Java/j145.java b/Java/j145.java deleted file mode 100644 index da8ac1cd..00000000 --- a/Java/j145.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - String s = "hello"; - s.concat("world"); - System.out.println(s); - } -} diff --git a/Java/j146.java b/Java/j146.java deleted file mode 100644 index 78dc9f7e..00000000 --- a/Java/j146.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = 5; - if (x > 0) - System.out.println("Positive"); - System.out.println("Always printed"); - } -} diff --git a/Java/j147.java b/Java/j147.java deleted file mode 100644 index 1dd31ae2..00000000 --- a/Java/j147.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] arr = new int[3]{1, 2, 3}; - System.out.println(arr[0]); - } -} diff --git a/Java/j148.java b/Java/j148.java deleted file mode 100644 index eaee4844..00000000 --- a/Java/j148.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String name; - System.out.println(name); - } -} diff --git a/Java/j149.java b/Java/j149.java deleted file mode 100644 index fb97dc15..00000000 --- a/Java/j149.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - double x = 5.0; - int result = x; - System.out.println(result); - } -} diff --git a/Java/j15.java b/Java/j15.java deleted file mode 100644 index 4c38504c..00000000 --- a/Java/j15.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - boolean isValid = 0; - System.out.println(isValid); - } -} diff --git a/Java/j150.java b/Java/j150.java deleted file mode 100644 index 50d04347..00000000 --- a/Java/j150.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - int num = 10; - if (num = 10) { - System.out.println("Number is 10"); - } - } -} diff --git a/Java/j151.java b/Java/j151.java deleted file mode 100644 index 1f455e30..00000000 --- a/Java/j151.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] arr = new int[3]; - for (int i : arr) { - arr[i] = i * 2; - } - } -} diff --git a/Java/j152.java b/Java/j152.java deleted file mode 100644 index e883b0b7..00000000 --- a/Java/j152.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] arr = {1, 2, 3}; - arr[3] = 10; - } -} diff --git a/Java/j153.java b/Java/j153.java deleted file mode 100644 index e28e908d..00000000 --- a/Java/j153.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 5; - System.out.println(a = 10); - } -} diff --git a/Java/j154.java b/Java/j154.java deleted file mode 100644 index d3324af5..00000000 --- a/Java/j154.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 10; - int b = 0; - int result = a / b; - System.out.println(result); - } -} diff --git a/Java/j155.java b/Java/j155.java deleted file mode 100644 index 2410b07f..00000000 --- a/Java/j155.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = 10; - System.out.println(x.equals(10)); - } -} diff --git a/Java/j156.java b/Java/j156.java deleted file mode 100644 index fb2e0bdf..00000000 --- a/Java/j156.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - double x = 10 / 0; - System.out.println(x); - } -} diff --git a/Java/j157.java b/Java/j157.java deleted file mode 100644 index bcea9397..00000000 --- a/Java/j157.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - String text = "Java"; - char firstChar = text[0]; - System.out.println(firstChar); - } -} diff --git a/Java/j158.java b/Java/j158.java deleted file mode 100644 index 0d6b64e1..00000000 --- a/Java/j158.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = 5; - System.out.println(x ? "Positive" : "Negative"); - } -} diff --git a/Java/j159.java b/Java/j159.java deleted file mode 100644 index dbe4f37b..00000000 --- a/Java/j159.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - String str = "123"; - int number = Integer.toInt(str); - System.out.println(number); - } -} diff --git a/Java/j16.java b/Java/j16.java deleted file mode 100644 index c7b34e94..00000000 --- a/Java/j16.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 5; - int b = 10; - System.out.println(a > b ? "Greater" : "Smaller"); - else System.out.println("Equal"); - } -} diff --git a/Java/j160.java b/Java/j160.java deleted file mode 100644 index 29166d2d..00000000 --- a/Java/j160.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] arr = {1, 2, 3}; - System.out.println(arr(0)); - } -} diff --git a/Java/j161.java b/Java/j161.java deleted file mode 100644 index 592c8748..00000000 --- a/Java/j161.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - boolean isTrue = false; - if (isTrue = true) { - System.out.println("True"); - } - } -} diff --git a/Java/j162.java b/Java/j162.java deleted file mode 100644 index 50147011..00000000 --- a/Java/j162.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 10; - float b = 10.5; - int c = a + b; - System.out.println(c); - } -} diff --git a/Java/j163.java b/Java/j163.java deleted file mode 100644 index 7b4b85f0..00000000 --- a/Java/j163.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String text = "Hello"; - System.out.println(text.subString(1, 4)); - } -} diff --git a/Java/j164.java b/Java/j164.java deleted file mode 100644 index 59202072..00000000 --- a/Java/j164.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] arr = new int[3]; - arr.length(); - } -} diff --git a/Java/j165.java b/Java/j165.java deleted file mode 100644 index c6096f98..00000000 --- a/Java/j165.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 5; - System.out.println(a++ + ++a); - } -} diff --git a/Java/j166.java b/Java/j166.java deleted file mode 100644 index 110543be..00000000 --- a/Java/j166.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - List list = new ArrayList<>(); - list.add("Alice"); - System.out.println(list[0]); - } -} diff --git a/Java/j167.java b/Java/j167.java deleted file mode 100644 index 79f76aca..00000000 --- a/Java/j167.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - String text = "apple"; - text.charAt(5); - System.out.println(text); - } -} diff --git a/Java/j168.java b/Java/j168.java deleted file mode 100644 index 0fdc631e..00000000 --- a/Java/j168.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - double value = 1 / 2; - System.out.println(value); - } -} diff --git a/Java/j169.java b/Java/j169.java deleted file mode 100644 index 4372f8ab..00000000 --- a/Java/j169.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] numbers = {1, 2, 3}; - System.out.println(Arrays.toString(numbers)); - } -} diff --git a/Java/j17.java b/Java/j17.java deleted file mode 100644 index a6d9e74d..00000000 --- a/Java/j17.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int value = null; - System.out.println(value); - } -} diff --git a/Java/j170.java b/Java/j170.java deleted file mode 100644 index 6fe100df..00000000 --- a/Java/j170.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - for (int i = 0; i++) { - System.out.println(i); - } - } -} diff --git a/Java/j171.java b/Java/j171.java deleted file mode 100644 index 21780bb5..00000000 --- a/Java/j171.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String name = "John"; - System.out.println(name.indexOf()); - } -} diff --git a/Java/j172.java b/Java/j172.java deleted file mode 100644 index a85f7153..00000000 --- a/Java/j172.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 5; - boolean b = (a = 10); - System.out.println(b); - } -} diff --git a/Java/j173.java b/Java/j173.java deleted file mode 100644 index 57e8a1b0..00000000 --- a/Java/j173.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String text = null; - System.out.println(text.isEmpty()); - } -} diff --git a/Java/j174.java b/Java/j174.java deleted file mode 100644 index 7b9b96d6..00000000 --- a/Java/j174.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 5; - String result = Integer.toInt(a); - System.out.println(result); - } -} diff --git a/Java/j175.java b/Java/j175.java deleted file mode 100644 index a72a9e5b..00000000 --- a/Java/j175.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = 10; - System.out.println((double) x / 0); - } -} diff --git a/Java/j176.java b/Java/j176.java deleted file mode 100644 index e1549a3d..00000000 --- a/Java/j176.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 10; - System.out.println(a instanceof Integer); - } -} diff --git a/Java/j177.java b/Java/j177.java deleted file mode 100644 index 23df4d81..00000000 --- a/Java/j177.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - boolean flag = true; - if (flag = false) { - System.out.println("True"); - } - } -} diff --git a/Java/j178.java b/Java/j178.java deleted file mode 100644 index ff52a4d9..00000000 --- a/Java/j178.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String str = 100; - System.out.println(str); - } -} diff --git a/Java/j179.java b/Java/j179.java deleted file mode 100644 index ed2503fe..00000000 --- a/Java/j179.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - List list = new ArrayList<>(); - list.add("Hello"); - list.add(5); - } -} diff --git a/Java/j18.java b/Java/j18.java deleted file mode 100644 index 2f2cc5fe..00000000 --- a/Java/j18.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - Integer x = 1000; - if (x == 1000) { - System.out.println("Equal"); - } - } -} diff --git a/Java/j180.java b/Java/j180.java deleted file mode 100644 index ccad6126..00000000 --- a/Java/j180.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = 5; - String result = Integer.parseInt(x); - System.out.println(result); - } -} diff --git a/Java/j181.java b/Java/j181.java deleted file mode 100644 index 553c4d00..00000000 --- a/Java/j181.java +++ /dev/null @@ -1,5 +0,0 @@ -public class Main { - public static void main(String[] args) { - System.out.println(Math.pow(2)); - } -} diff --git a/Java/j182.java b/Java/j182.java deleted file mode 100644 index 4a090e80..00000000 --- a/Java/j182.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - String text = "Java"; - text.replace("a", 'o'); - System.out.println(text); - } -} diff --git a/Java/j183.java b/Java/j183.java deleted file mode 100644 index 7a0e14bb..00000000 --- a/Java/j183.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - String[] arr = {"one", "two", "three"}; - for (String i = arr) { - System.out.println(i); - } - } -} diff --git a/Java/j184.java b/Java/j184.java deleted file mode 100644 index 365f7630..00000000 --- a/Java/j184.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - String text = "hello"; - text.charAt(10); - System.out.println(text); - } -} diff --git a/Java/j185.java b/Java/j185.java deleted file mode 100644 index 98f05d54..00000000 --- a/Java/j185.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 5; - String result = a.toString(); - System.out.println(result); - } -} diff --git a/Java/j186.java b/Java/j186.java deleted file mode 100644 index c2892352..00000000 --- a/Java/j186.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 5; - int b = 10; - System.out.println(a = b ? "Equal" : "Not Equal"); - } -} diff --git a/Java/j187.java b/Java/j187.java deleted file mode 100644 index c537eb1f..00000000 --- a/Java/j187.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String[] items = {"Apple", "Orange"}; - System.out.println(items[-1]); - } -} diff --git a/Java/j188.java b/Java/j188.java deleted file mode 100644 index 1d16164b..00000000 --- a/Java/j188.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] arr = new int[5]; - for (int i = 0; i < arr.size(); i++) { - System.out.println(arr[i]); - } - } -} diff --git a/Java/j189.java b/Java/j189.java deleted file mode 100644 index f72f5930..00000000 --- a/Java/j189.java +++ /dev/null @@ -1,10 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 5; - if (a > 10) - System.out.println("a is greater than 10"); - else - System.out.println("a is less than 10"); - System.out.println("This will always print"); - } -} diff --git a/Java/j19.java b/Java/j19.java deleted file mode 100644 index a48c579a..00000000 --- a/Java/j19.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] arr = new int[5]; - arr.add(10); - System.out.println(arr[0]); - } -} diff --git a/Java/j190.java b/Java/j190.java deleted file mode 100644 index d97ad27e..00000000 --- a/Java/j190.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = Math.max(); - System.out.println(x); - } -} diff --git a/Java/j191.java b/Java/j191.java deleted file mode 100644 index 6996ccbb..00000000 --- a/Java/j191.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 5; - double b = 10.5; - System.out.println(a + (String) b); - } -} diff --git a/Java/j192.java b/Java/j192.java deleted file mode 100644 index d4e56bf5..00000000 --- a/Java/j192.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - double x = 5 / 2; - System.out.println(x); - } -} diff --git a/Java/j193.java b/Java/j193.java deleted file mode 100644 index 3c736152..00000000 --- a/Java/j193.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String[] arr = {"A", "B", "C"}; - System.out.println(arr.length()); - } -} diff --git a/Java/j194.java b/Java/j194.java deleted file mode 100644 index 38890e5c..00000000 --- a/Java/j194.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] numbers = new int[5]; - System.out.println(numbers.size()); - } -} diff --git a/Java/j195.java b/Java/j195.java deleted file mode 100644 index 8e600a52..00000000 --- a/Java/j195.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - List numbers = new ArrayList<>(); - System.out.println(numbers); - } -} diff --git a/Java/j196.java b/Java/j196.java deleted file mode 100644 index 3e08f39d..00000000 --- a/Java/j196.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - String message = "Hello"; - message.concat("World"); - System.out.println(message); - } -} diff --git a/Java/j197.java b/Java/j197.java deleted file mode 100644 index fa75f2c2..00000000 --- a/Java/j197.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = 100; - System.out.println(x ? "Yes" : "No"); - } -} diff --git a/Java/j198.java b/Java/j198.java deleted file mode 100644 index 512b4770..00000000 --- a/Java/j198.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] nums = new int[5]; - nums.add(10); - System.out.println(nums[0]); - } -} diff --git a/Java/j199.java b/Java/j199.java deleted file mode 100644 index 691e4d52..00000000 --- a/Java/j199.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String text = "abc"; - System.out.println(text.charAt(5)); - } -} diff --git a/Java/j2.java b/Java/j2.java deleted file mode 100644 index 465a2dc8..00000000 --- a/Java/j2.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] numbers = {1, 2, 3}; - System.out.println(numbers(0)); - } -} diff --git a/Java/j20.java b/Java/j20.java deleted file mode 100644 index effdaa79..00000000 --- a/Java/j20.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] numbers = new int[-10]; - System.out.println(numbers.length); - } -} diff --git a/Java/j200.java b/Java/j200.java deleted file mode 100644 index 81d07e4f..00000000 --- a/Java/j200.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = 10; - double y = 0; - System.out.println(x / y); - } -} diff --git a/Java/j201.java b/Java/j201.java deleted file mode 100644 index 281ff6b5..00000000 --- a/Java/j201.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String[] fruits = new String[5]; - fruits[5] = "Apple"; - } -} diff --git a/Java/j202.java b/Java/j202.java deleted file mode 100644 index f5b3ed42..00000000 --- a/Java/j202.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - boolean result = (5 == 5 ? "true" : "false"); - System.out.println(result); - } -} diff --git a/Java/j203.java b/Java/j203.java deleted file mode 100644 index e7bff523..00000000 --- a/Java/j203.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 5; - double b = 0; - int result = a / b; - System.out.println(result); - } -} diff --git a/Java/j204.java b/Java/j204.java deleted file mode 100644 index 19f1b1b0..00000000 --- a/Java/j204.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - double result = Math.pow(2); - System.out.println(result); - } -} diff --git a/Java/j205.java b/Java/j205.java deleted file mode 100644 index 742cd3c0..00000000 --- a/Java/j205.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 5; - System.out.println(a + " " + Math.pow(a, 2)); - } -} diff --git a/Java/j206.java b/Java/j206.java deleted file mode 100644 index b3373a05..00000000 --- a/Java/j206.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - List names = new ArrayList<>(); - names.add("Alice", "Bob"); - System.out.println(names); - } -} diff --git a/Java/j207.java b/Java/j207.java deleted file mode 100644 index 016b1f2e..00000000 --- a/Java/j207.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = 10; - System.out.println("x is " x); - } -} diff --git a/Java/j208.java b/Java/j208.java deleted file mode 100644 index e50af3ed..00000000 --- a/Java/j208.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - char ch = "Hello"; - System.out.println(ch); - } -} diff --git a/Java/j209.java b/Java/j209.java deleted file mode 100644 index 89b504c8..00000000 --- a/Java/j209.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] arr = new int[-5]; - System.out.println(arr.length); - } -} diff --git a/Java/j21.java b/Java/j21.java deleted file mode 100644 index 618ab414..00000000 --- a/Java/j21.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - for (int i = 0; i < 10, i++) { - System.out.println(i); - } - } -} diff --git a/Java/j210.java b/Java/j210.java deleted file mode 100644 index 0f51e68d..00000000 --- a/Java/j210.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - double value = 3.14; - int x = value; - System.out.println(x); - } -} diff --git a/Java/j211.java b/Java/j211.java deleted file mode 100644 index ff9dc6f6..00000000 --- a/Java/j211.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = 5; - if (x == 5); - System.out.println("x is 5"); - } -} diff --git a/Java/j212.java b/Java/j212.java deleted file mode 100644 index 2afcec8c..00000000 --- a/Java/j212.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = "100"; - System.out.println(a); - } -} diff --git a/Java/j213.java b/Java/j213.java deleted file mode 100644 index c20f4564..00000000 --- a/Java/j213.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String[] arr = new String[3]; - System.out.println(arr.size()); - } -} diff --git a/Java/j214.java b/Java/j214.java deleted file mode 100644 index 13e57a3b..00000000 --- a/Java/j214.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 5; - double b = 10.5; - int c = a + b; - System.out.println(c); - } -} diff --git a/Java/j215.java b/Java/j215.java deleted file mode 100644 index 3e91deef..00000000 --- a/Java/j215.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String text = "abc"; - System.out.println(text.substring(4)); - } -} diff --git a/Java/j216.java b/Java/j216.java deleted file mode 100644 index 0f2aa86c..00000000 --- a/Java/j216.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String[] arr = new String[] {"A", "B", "C"}; - System.out.println(arr.get(0)); - } -} diff --git a/Java/j217.java b/Java/j217.java deleted file mode 100644 index 76c9c803..00000000 --- a/Java/j217.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - String text = "hello"; - char ch = text.charAt(6); - System.out.println(ch); - } -} diff --git a/Java/j218.java b/Java/j218.java deleted file mode 100644 index 4e0091b2..00000000 --- a/Java/j218.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = 5; - double result = x / 0; - System.out.println(result); - } -} diff --git a/Java/j219.java b/Java/j219.java deleted file mode 100644 index 170540b5..00000000 --- a/Java/j219.java +++ /dev/null @@ -1,5 +0,0 @@ -public class Main { - public static void main(String[] args) { - System.out.println(Math.sqrt(-1)); - } -} diff --git a/Java/j22.java b/Java/j22.java deleted file mode 100644 index a279fb68..00000000 --- a/Java/j22.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] arr = new int[5]; - System.out.println(arr.size()); - } -} diff --git a/Java/j220.java b/Java/j220.java deleted file mode 100644 index 38fcf1b9..00000000 --- a/Java/j220.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - double x = 5 / 0; - System.out.println(x); - } -} diff --git a/Java/j221.java b/Java/j221.java deleted file mode 100644 index e883b0b7..00000000 --- a/Java/j221.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] arr = {1, 2, 3}; - arr[3] = 10; - } -} diff --git a/Java/j222.java b/Java/j222.java deleted file mode 100644 index f6b4e353..00000000 --- a/Java/j222.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String name = null; - System.out.println(name.isEmpty()); - } -} diff --git a/Java/j223.java b/Java/j223.java deleted file mode 100644 index 92f39cc0..00000000 --- a/Java/j223.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - String text = "Java"; - text.toUppercase(); - System.out.println(text); - } -} diff --git a/Java/j224.java b/Java/j224.java deleted file mode 100644 index b8e95e0d..00000000 --- a/Java/j224.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 5; - boolean result = (a = 10); - System.out.println(result); - } -} diff --git a/Java/j225.java b/Java/j225.java deleted file mode 100644 index eb3f86fb..00000000 --- a/Java/j225.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - String name = "Alice"; - char letter = name.charAt(10); - System.out.println(letter); - } -} diff --git a/Java/j226.java b/Java/j226.java deleted file mode 100644 index d4e56bf5..00000000 --- a/Java/j226.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - double x = 5 / 2; - System.out.println(x); - } -} diff --git a/Java/j227.java b/Java/j227.java deleted file mode 100644 index c81307bf..00000000 --- a/Java/j227.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = null; - System.out.println(x); - } -} diff --git a/Java/j228.java b/Java/j228.java deleted file mode 100644 index 9eb01975..00000000 --- a/Java/j228.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String message = "Hello World"; - System.out.println(message.charAt(11)); - } -} diff --git a/Java/j229.java b/Java/j229.java deleted file mode 100644 index 59202072..00000000 --- a/Java/j229.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] arr = new int[3]; - arr.length(); - } -} diff --git a/Java/j23.java b/Java/j23.java deleted file mode 100644 index 323126a4..00000000 --- a/Java/j23.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = "10"; - System.out.println(a); - } -} diff --git a/Java/j230.java b/Java/j230.java deleted file mode 100644 index 5e8221a7..00000000 --- a/Java/j230.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - List fruits = new ArrayList<>(); - fruits.add("Apple"); - fruits(0) = "Banana"; - } -} diff --git a/Java/j231.java b/Java/j231.java deleted file mode 100644 index c6397e94..00000000 --- a/Java/j231.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - String text = "Java"; - text.replace('a', "b"); - System.out.println(text); - } -} diff --git a/Java/j232.java b/Java/j232.java deleted file mode 100644 index 9148ad10..00000000 --- a/Java/j232.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - double value = Math.sqrt(25); - int result = value; - System.out.println(result); - } -} diff --git a/Java/j233.java b/Java/j233.java deleted file mode 100644 index 6a188364..00000000 --- a/Java/j233.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 10; - Integer b = null; - int result = a + b; - System.out.println(result); - } -} diff --git a/Java/j234.java b/Java/j234.java deleted file mode 100644 index 7fef1b77..00000000 --- a/Java/j234.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String s = "Java"; - System.out.println(s.charAt(4)); - } -} diff --git a/Java/j235.java b/Java/j235.java deleted file mode 100644 index e1cc0736..00000000 --- a/Java/j235.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = 10; - System.out.println(x ? "Yes" : "No"); - } -} diff --git a/Java/j236.java b/Java/j236.java deleted file mode 100644 index 465a2dc8..00000000 --- a/Java/j236.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] numbers = {1, 2, 3}; - System.out.println(numbers(0)); - } -} diff --git a/Java/j237.java b/Java/j237.java deleted file mode 100644 index dfcdda03..00000000 --- a/Java/j237.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - double result = Math.pow(5); - System.out.println(result); - } -} diff --git a/Java/j238.java b/Java/j238.java deleted file mode 100644 index 2c5342d4..00000000 --- a/Java/j238.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - String str = null; - if (str.equals("Hello")) { - System.out.println("Hello"); - } - } -} diff --git a/Java/j239.java b/Java/j239.java deleted file mode 100644 index e1549a3d..00000000 --- a/Java/j239.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 10; - System.out.println(a instanceof Integer); - } -} diff --git a/Java/j24.java b/Java/j24.java deleted file mode 100644 index 512b4770..00000000 --- a/Java/j24.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] nums = new int[5]; - nums.add(10); - System.out.println(nums[0]); - } -} diff --git a/Java/j240.java b/Java/j240.java deleted file mode 100644 index 7c6ca477..00000000 --- a/Java/j240.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - double num = 5 / 2; - System.out.println(num); - } -} diff --git a/Java/j241.java b/Java/j241.java deleted file mode 100644 index 37264826..00000000 --- a/Java/j241.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String[] arr = {"A", "B", "C"}; - arr[3] = "D"; - } -} diff --git a/Java/j242.java b/Java/j242.java deleted file mode 100644 index 1dd31ae2..00000000 --- a/Java/j242.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] arr = new int[3]{1, 2, 3}; - System.out.println(arr[0]); - } -} diff --git a/Java/j243.java b/Java/j243.java deleted file mode 100644 index 0b244a81..00000000 --- a/Java/j243.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String message = "Hello, World!"; - System.out.println(message.substring(1, 20)); - } -} diff --git a/Java/j244.java b/Java/j244.java deleted file mode 100644 index 04d37169..00000000 --- a/Java/j244.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = Math.abs(); - System.out.println(x); - } -} diff --git a/Java/j245.java b/Java/j245.java deleted file mode 100644 index 7b4b85f0..00000000 --- a/Java/j245.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String text = "Hello"; - System.out.println(text.subString(1, 4)); - } -} diff --git a/Java/j246.java b/Java/j246.java deleted file mode 100644 index b69cb5e5..00000000 --- a/Java/j246.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - String message = "Hello"; - message.replace('e', "a"); - System.out.println(message); - } -} diff --git a/Java/j247.java b/Java/j247.java deleted file mode 100644 index c7b0ba76..00000000 --- a/Java/j247.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - String str = null; - if (str.equals("Hello")) { - System.out.println("Text is Hello"); - } - } -} diff --git a/Java/j248.java b/Java/j248.java deleted file mode 100644 index d4e56bf5..00000000 --- a/Java/j248.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - double x = 5 / 2; - System.out.println(x); - } -} diff --git a/Java/j249.java b/Java/j249.java deleted file mode 100644 index 0d6b64e1..00000000 --- a/Java/j249.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = 5; - System.out.println(x ? "Positive" : "Negative"); - } -} diff --git a/Java/j25.java b/Java/j25.java deleted file mode 100644 index 4cac3959..00000000 --- a/Java/j25.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - String name = "John"; - name.toUpperCase; - System.out.println(name); - } -} diff --git a/Java/j250.java b/Java/j250.java deleted file mode 100644 index e1226d9d..00000000 --- a/Java/j250.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - char c = "A"; - System.out.println(c); - } -} diff --git a/Java/j26.java b/Java/j26.java deleted file mode 100644 index 46fc41eb..00000000 --- a/Java/j26.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = 10; - System.out.println(x.toString()); - } -} diff --git a/Java/j27.java b/Java/j27.java deleted file mode 100644 index 5fed2e72..00000000 --- a/Java/j27.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] numbers = new int[5]; - for (int i = 0; i <= 5; i++) { - numbers[i] = i; - } - } -} diff --git a/Java/j28.java b/Java/j28.java deleted file mode 100644 index 3e7a2697..00000000 --- a/Java/j28.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] arr = new int[5]; - arr[0] = "100"; - System.out.println(arr[0]); - } -} diff --git a/Java/j29.java b/Java/j29.java deleted file mode 100644 index f95ecfa5..00000000 --- a/Java/j29.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 5; - int b = "5"; - System.out.println(a + b); - } -} diff --git a/Java/j3.java b/Java/j3.java deleted file mode 100644 index eaee4844..00000000 --- a/Java/j3.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String name; - System.out.println(name); - } -} diff --git a/Java/j30.java b/Java/j30.java deleted file mode 100644 index e71267cb..00000000 --- a/Java/j30.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - double x = Math.sqrt(-1); - System.out.println(x); - } -} diff --git a/Java/j31.java b/Java/j31.java deleted file mode 100644 index 93b9c2da..00000000 --- a/Java/j31.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 5; - System.out.println(a++ * ++a); - } -} diff --git a/Java/j32.java b/Java/j32.java deleted file mode 100644 index 281f2ca2..00000000 --- a/Java/j32.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 5; - Integer b = null; - System.out.println(a + b); - } -} diff --git a/Java/j33.java b/Java/j33.java deleted file mode 100644 index e2d9bbb5..00000000 --- a/Java/j33.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String s = "hello"; - System.out.println(s.reverse()); - } -} diff --git a/Java/j34.java b/Java/j34.java deleted file mode 100644 index 8df564ce..00000000 --- a/Java/j34.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int num = 5; - num.equals(5); - } -} diff --git a/Java/j35.java b/Java/j35.java deleted file mode 100644 index 6cb75edb..00000000 --- a/Java/j35.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String name = null; - System.out.println(name.length()); - } -} diff --git a/Java/j36.java b/Java/j36.java deleted file mode 100644 index 1f220432..00000000 --- a/Java/j36.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] arr = {1, 2, 3}; - System.out.println(arr.toString()); - } -} diff --git a/Java/j37.java b/Java/j37.java deleted file mode 100644 index a5bd38f2..00000000 --- a/Java/j37.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 5; - a++; - System.out.println(++a++); - } -} diff --git a/Java/j38.java b/Java/j38.java deleted file mode 100644 index a120ebe6..00000000 --- a/Java/j38.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] arr = new int[5]; - System.out.println(arr(0)); - } -} diff --git a/Java/j39.java b/Java/j39.java deleted file mode 100644 index 17e810ca..00000000 --- a/Java/j39.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = Math.pow(2, 3); - System.out.println(x); - } -} diff --git a/Java/j4.java b/Java/j4.java deleted file mode 100644 index 72a2b101..00000000 --- a/Java/j4.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - List names = new ArrayList<>(); - names.add("Alice"); - System.out.println(names[0]); - } -} diff --git a/Java/j40.java b/Java/j40.java deleted file mode 100644 index 9ac71510..00000000 --- a/Java/j40.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = "100"; - System.out.println(x); - } -} diff --git a/Java/j41.java b/Java/j41.java deleted file mode 100644 index 04077b2d..00000000 --- a/Java/j41.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - List list = new ArrayList<>(); - list.add("apple"); - System.out.println(list[0]); - } -} diff --git a/Java/j42.java b/Java/j42.java deleted file mode 100644 index 553c4d00..00000000 --- a/Java/j42.java +++ /dev/null @@ -1,5 +0,0 @@ -public class Main { - public static void main(String[] args) { - System.out.println(Math.pow(2)); - } -} diff --git a/Java/j43.java b/Java/j43.java deleted file mode 100644 index e3f960ad..00000000 --- a/Java/j43.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String s = "Java"; - System.out.println(s.length(5)); - } -} diff --git a/Java/j44.java b/Java/j44.java deleted file mode 100644 index 4c4c37d7..00000000 --- a/Java/j44.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - List items = new ArrayList<>(); - items.add("Item1"); - System.out.println(items(0)); - } -} diff --git a/Java/j45.java b/Java/j45.java deleted file mode 100644 index f9648642..00000000 --- a/Java/j45.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - double x = 5.0 / 0; - System.out.println(x); - } -} diff --git a/Java/j46.java b/Java/j46.java deleted file mode 100644 index fef86177..00000000 --- a/Java/j46.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - boolean isTrue = True; - System.out.println(isTrue); - } -} diff --git a/Java/j47.java b/Java/j47.java deleted file mode 100644 index ee629d44..00000000 --- a/Java/j47.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 5; - int result = Math.pow(a); - System.out.println(result); - } -} diff --git a/Java/j48.java b/Java/j48.java deleted file mode 100644 index 8efcdd08..00000000 --- a/Java/j48.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = 5 / 0; - System.out.println(x); - } -} diff --git a/Java/j49.java b/Java/j49.java deleted file mode 100644 index 7541cfb5..00000000 --- a/Java/j49.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - List numbers = new ArrayList<>(); - numbers.add(10); - System.out.println(numbers.get(0)); - } -} diff --git a/Java/j5.java b/Java/j5.java deleted file mode 100644 index f23bd213..00000000 --- a/Java/j5.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] arr = {1, 2, 3}; - System.out.println(arr); - } -} diff --git a/Java/j50.java b/Java/j50.java deleted file mode 100644 index 94e60da2..00000000 --- a/Java/j50.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String name = "Java"; - System.out.println(name.indexOf(2)); - } -} diff --git a/Java/j51.java b/Java/j51.java deleted file mode 100644 index 79e32c7c..00000000 --- a/Java/j51.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - int number = 5; - if (number = 5) { - System.out.println("Number is 5"); - } - } -} diff --git a/Java/j52.java b/Java/j52.java deleted file mode 100644 index 9da5b660..00000000 --- a/Java/j52.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 10; - String s = 'Hello'; - } -} diff --git a/Java/j53.java b/Java/j53.java deleted file mode 100644 index f8e9057a..00000000 --- a/Java/j53.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] arr = new int[5]; - arr[5] = 10; - } -} diff --git a/Java/j54.java b/Java/j54.java deleted file mode 100644 index a3b4bdb7..00000000 --- a/Java/j54.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - for (int i = 0; i < 10 i++) { - System.out.println(i); - } - } -} diff --git a/Java/j55.java b/Java/j55.java deleted file mode 100644 index 2ec2adee..00000000 --- a/Java/j55.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String greeting = Hello; - System.out.println(greeting); - } -} diff --git a/Java/j56.java b/Java/j56.java deleted file mode 100644 index b26a30ef..00000000 --- a/Java/j56.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = 1; - double y = x / 0; - System.out.println(y); - } -} diff --git a/Java/j57.java b/Java/j57.java deleted file mode 100644 index 2ec2adee..00000000 --- a/Java/j57.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String greeting = Hello; - System.out.println(greeting); - } -} diff --git a/Java/j58.java b/Java/j58.java deleted file mode 100644 index ba2a4989..00000000 --- a/Java/j58.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - String message = "Hello, World!"; - char c = message.charAt(20); - System.out.println(c); - } -} diff --git a/Java/j59.java b/Java/j59.java deleted file mode 100644 index 7ebdbe61..00000000 --- a/Java/j59.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String[] fruits = {"Apple", "Banana", "Mango"}; - System.out.println(fruits[-1]); - } -} diff --git a/Java/j6.java b/Java/j6.java deleted file mode 100644 index d2f4d7a0..00000000 --- a/Java/j6.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String s = "abc"; - System.out.println(s.charAt(5)); - } -} diff --git a/Java/j60.java b/Java/j60.java deleted file mode 100644 index cd25b0ca..00000000 --- a/Java/j60.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 10, b = 0; - int result = a / b; - System.out.println(result); - } -} diff --git a/Java/j61.java b/Java/j61.java deleted file mode 100644 index d5df4b28..00000000 --- a/Java/j61.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] arr = new int[5]; - for (int i : arr) { - arr[i] = i * 2; - } - } -} diff --git a/Java/j62.java b/Java/j62.java deleted file mode 100644 index 791e7117..00000000 --- a/Java/j62.java +++ /dev/null @@ -1,9 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = 10; - while x > 0 { - System.out.println(x); - x--; - } - } -} diff --git a/Java/j63.java b/Java/j63.java deleted file mode 100644 index 510643e3..00000000 --- a/Java/j63.java +++ /dev/null @@ -1,11 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = 5; - switch (x) { - case 5: - System.out.println("Five"); - default: - System.out.println("Default case"); - } - } -} diff --git a/Java/j64.java b/Java/j64.java deleted file mode 100644 index 08ac285f..00000000 --- a/Java/j64.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] arr = new int[10]; - System.out.println(arr.length()); - } -} diff --git a/Java/j65.java b/Java/j65.java deleted file mode 100644 index 5133658e..00000000 --- a/Java/j65.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - double pi = 3.14159; - double radius = 5.0; - double area = Math.pi * radius * radius; - System.out.println(area); - } -} diff --git a/Java/j66.java b/Java/j66.java deleted file mode 100644 index 04e67736..00000000 --- a/Java/j66.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 5; - int b = '10'; - System.out.println(a + b); - } -} diff --git a/Java/j67.java b/Java/j67.java deleted file mode 100644 index 1f4dfd2c..00000000 --- a/Java/j67.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String str = null; - System.out.println(str.length()); - } -} diff --git a/Java/j68.java b/Java/j68.java deleted file mode 100644 index 1fee6d93..00000000 --- a/Java/j68.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - char ch = "A"; - System.out.println(ch); - } -} diff --git a/Java/j69.java b/Java/j69.java deleted file mode 100644 index 2410b07f..00000000 --- a/Java/j69.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = 10; - System.out.println(x.equals(10)); - } -} diff --git a/Java/j7.java b/Java/j7.java deleted file mode 100644 index ab976e15..00000000 --- a/Java/j7.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] nums = new int[-5]; - System.out.println(nums.length); - } -} diff --git a/Java/j70.java b/Java/j70.java deleted file mode 100644 index 0761fafe..00000000 --- a/Java/j70.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - String s = "hello"; - s.toUppercase(); - System.out.println(s); - } -} diff --git a/Java/j71.java b/Java/j71.java deleted file mode 100644 index 92f65700..00000000 --- a/Java/j71.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int result = 5 + ; - System.out.println(result); - } -} diff --git a/Java/j72.java b/Java/j72.java deleted file mode 100644 index cd802d95..00000000 --- a/Java/j72.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - String[] names = {"John", "Doe"}; - for (int i = 0; i < names.size(); i++) { - System.out.println(names[i]); - } - } -} diff --git a/Java/j73.java b/Java/j73.java deleted file mode 100644 index 749cd12f..00000000 --- a/Java/j73.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - int x = 5; - double y = 0.0; - double result = x % y; - System.out.println(result); - } -} diff --git a/Java/j74.java b/Java/j74.java deleted file mode 100644 index 81d69ba2..00000000 --- a/Java/j74.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 100; - byte b = a; - System.out.println(b); - } -} diff --git a/Java/j75.java b/Java/j75.java deleted file mode 100644 index 330bab44..00000000 --- a/Java/j75.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 10; - Integer b = null; - int c = b + a; - System.out.println(c); - } -} diff --git a/Java/j76.java b/Java/j76.java deleted file mode 100644 index 76303a87..00000000 --- a/Java/j76.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - for (int i = 0; i < 10; i++); - System.out.println(i); - } -} diff --git a/Java/j77.java b/Java/j77.java deleted file mode 100644 index e71267cb..00000000 --- a/Java/j77.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - double x = Math.sqrt(-1); - System.out.println(x); - } -} diff --git a/Java/j78.java b/Java/j78.java deleted file mode 100644 index ae5b523a..00000000 --- a/Java/j78.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - Object obj = "Hello"; - int num = (int) obj; - System.out.println(num); - } -} diff --git a/Java/j79.java b/Java/j79.java deleted file mode 100644 index 323126a4..00000000 --- a/Java/j79.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = "10"; - System.out.println(a); - } -} diff --git a/Java/j8.java b/Java/j8.java deleted file mode 100644 index 0e12d9b4..00000000 --- a/Java/j8.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 5; - double result = Math.pow(a); - System.out.println(result); - } -} diff --git a/Java/j80.java b/Java/j80.java deleted file mode 100644 index 00792c77..00000000 --- a/Java/j80.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 10; - a++; - System.out.println(a++); - } -} diff --git a/Java/j81.java b/Java/j81.java deleted file mode 100644 index e2299c31..00000000 --- a/Java/j81.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - String s = "hello"; - s = null; - System.out.println(s.toUpperCase()); - } -} diff --git a/Java/j82.java b/Java/j82.java deleted file mode 100644 index fee97c52..00000000 --- a/Java/j82.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 5; - String s = Integer.parseInt(a); - System.out.println(s); - } -} diff --git a/Java/j83.java b/Java/j83.java deleted file mode 100644 index 56eb400e..00000000 --- a/Java/j83.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - String s = "Java"; - s.replace('a', "o"); - System.out.println(s); - } -} diff --git a/Java/j84.java b/Java/j84.java deleted file mode 100644 index d7c341b2..00000000 --- a/Java/j84.java +++ /dev/null @@ -1,9 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 0; - while (a = 10) { - System.out.println(a); - a++; - } - } -} diff --git a/Java/j85.java b/Java/j85.java deleted file mode 100644 index 8fda5992..00000000 --- a/Java/j85.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String[] fruits = new String[]{"Apple", "Orange", "Banana"}; - System.out.println(fruits(0)); - } -} diff --git a/Java/j86.java b/Java/j86.java deleted file mode 100644 index 8a081f5b..00000000 --- a/Java/j86.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - int a = 1; - do { - System.out.println(a); - } while a < 10; - } -} diff --git a/Java/j87.java b/Java/j87.java deleted file mode 100644 index d95036c3..00000000 --- a/Java/j87.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String message = 'Hello World'; - System.out.println(message); - } -} diff --git a/Java/j88.java b/Java/j88.java deleted file mode 100644 index e682fd89..00000000 --- a/Java/j88.java +++ /dev/null @@ -1,5 +0,0 @@ -public class Main { - public static void main(String[] args) { - System.out.println("Sum of 5 and 10 is: " + 5 + 10); - } -} diff --git a/Java/j89.java b/Java/j89.java deleted file mode 100644 index d9c21db8..00000000 --- a/Java/j89.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] nums = {1, 2, 3}; - System.out.println(nums[-1]); - } -} diff --git a/Java/j9.java b/Java/j9.java deleted file mode 100644 index 5916015d..00000000 --- a/Java/j9.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] numbers = new int[3]; - numbers[0] = 5; - numbers[3] = 10; - } -} diff --git a/Java/j90.java b/Java/j90.java deleted file mode 100644 index b895ac41..00000000 --- a/Java/j90.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] arr = new int[5]; - System.out.println(arr.length()); - } -} diff --git a/Java/j91.java b/Java/j91.java deleted file mode 100644 index 1dd31ae2..00000000 --- a/Java/j91.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] arr = new int[3]{1, 2, 3}; - System.out.println(arr[0]); - } -} diff --git a/Java/j92.java b/Java/j92.java deleted file mode 100644 index d189b35e..00000000 --- a/Java/j92.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - double value = 10.5; - int result = value + 5; - System.out.println(result); - } -} diff --git a/Java/j93.java b/Java/j93.java deleted file mode 100644 index bfb9a4c3..00000000 --- a/Java/j93.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - public static void main(String[] args) { - String text = null; - if (text.equals("Hello")) { - System.out.println("Text is Hello"); - } - } -} diff --git a/Java/j94.java b/Java/j94.java deleted file mode 100644 index f01163e5..00000000 --- a/Java/j94.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - String result = 5 + 10; - System.out.println(result); - } -} diff --git a/Java/j95.java b/Java/j95.java deleted file mode 100644 index c2d6467a..00000000 --- a/Java/j95.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - char c = 'Hello'; - System.out.println(c); - } -} diff --git a/Java/j96.java b/Java/j96.java deleted file mode 100644 index 076bbfad..00000000 --- a/Java/j96.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - int i = 10; - System.out.println(++i++); - } -} diff --git a/Java/j97.java b/Java/j97.java deleted file mode 100644 index dd542d87..00000000 --- a/Java/j97.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - final int a = 5; - a = 10; - System.out.println(a); - } -} diff --git a/Java/j98.java b/Java/j98.java deleted file mode 100644 index a48c579a..00000000 --- a/Java/j98.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main { - public static void main(String[] args) { - int[] arr = new int[5]; - arr.add(10); - System.out.println(arr[0]); - } -} diff --git a/Java/j99.java b/Java/j99.java deleted file mode 100644 index d4e56bf5..00000000 --- a/Java/j99.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Main { - public static void main(String[] args) { - double x = 5 / 2; - System.out.println(x); - } -} diff --git a/Java/temp.txt b/Java/temp.txt index 5d72a670..8b137891 100644 --- a/Java/temp.txt +++ b/Java/temp.txt @@ -1 +1 @@ -"." + diff --git a/Python/Easy/1.py b/Python/Easy/1.py new file mode 100644 index 00000000..55fc210f --- /dev/null +++ b/Python/Easy/1.py @@ -0,0 +1,10 @@ +x = int(input("enter a number ")) +y = int(input("enter a number ")) +if x==10: + print(x) + +if y > 5: + print(y) + +for i in range(5): + print(i) diff --git a/Python/Easy/10.py b/Python/Easy/10.py new file mode 100644 index 00000000..952701b3 --- /dev/null +++ b/Python/Easy/10.py @@ -0,0 +1,4 @@ +x = [1, 2, 3] +y = [1, 2, 3] +if x is y: + print("x and y are the same") diff --git a/Python/Easy/100.py b/Python/Easy/100.py new file mode 100644 index 00000000..e7b5abfd --- /dev/null +++ b/Python/Easy/100.py @@ -0,0 +1,8 @@ +class Student: + def __init__(self, name, grade): + self.name = name + self.grade = grade + def __str__(self): + return f'{self.name} ({self.grade})' +student = Student('Alice', 90) +print(student.__str__()) \ No newline at end of file diff --git a/Python/Easy/11.py b/Python/Easy/11.py new file mode 100644 index 00000000..d6de0cf7 --- /dev/null +++ b/Python/Easy/11.py @@ -0,0 +1,9 @@ +def outer(): + x = 10 + def inner(): + global x # Error: x is local to outer and cannot be made global + x = 5 + inner() + print(x) + +outer() diff --git a/Python/Easy/12.py b/Python/Easy/12.py new file mode 100644 index 00000000..c81e351c --- /dev/null +++ b/Python/Easy/12.py @@ -0,0 +1,10 @@ +class Animal: + def speak(self): + print("Animal speaks") + +class Dog(Animal): + def speak(self, sound): + print(sound) + +dog = Dog() +dog.speak() diff --git a/Python/Easy/13.py b/Python/Easy/13.py new file mode 100644 index 00000000..292911a3 --- /dev/null +++ b/Python/Easy/13.py @@ -0,0 +1,5 @@ +time = 5 +g = 9.8 +distance = g * t ** 2 # Error: 't' is not defined, typo in variable name +print("Distance traveled in free fall:", distance) + diff --git a/Python/Easy/14.py b/Python/Easy/14.py new file mode 100644 index 00000000..db2aeb59 --- /dev/null +++ b/Python/Easy/14.py @@ -0,0 +1,4 @@ +import maths +print(math.pow(2,3) +import randoms # Incorrect module name +print(random.randint(1, 10)) diff --git a/Python/Easy/15.py b/Python/Easy/15.py new file mode 100644 index 00000000..bcd02701 --- /dev/null +++ b/Python/Easy/15.py @@ -0,0 +1,9 @@ +Import +print(random.randint(1,10) + +Import random # Error: Incorrect case, 'import' should be lowercase +print(random.randint(1, 10)) + +import # Incomplete import statement +print(math.sqrt(25)) + diff --git a/Python/Easy/16.py b/Python/Easy/16.py new file mode 100644 index 00000000..603ce70e --- /dev/null +++ b/Python/Easy/16.py @@ -0,0 +1,5 @@ +L=(1,2,3,4) +L.append(5) +my_tuple = (1, 2, 3) + +my_tuple.append(4) # 'tuple' object has no 'append' method diff --git a/Python/Easy/17.py b/Python/Easy/17.py new file mode 100644 index 00000000..43ca75fc --- /dev/null +++ b/Python/Easy/17.py @@ -0,0 +1,11 @@ +a=int(input(‘enter a num’)) +b=int(input(‘enter another number’)) +Sum=a+b +print(‘Sum=’,sum) +a = int(input("Enter first number: ")) +b = int(input("Enter second number: ")) + +Sum = a + b +print("Sum: ", Sum) # Incorrect print syntax for variables + + diff --git a/Python/Easy/18.py b/Python/Easy/18.py new file mode 100644 index 00000000..a887bab5 --- /dev/null +++ b/Python/Easy/18.py @@ -0,0 +1,4 @@ +x = 5 +y = 10 +if x < 10 || y > 5: + print("x is less than 10 or y is greater than 5") diff --git a/Python/Easy/19.py b/Python/Easy/19.py new file mode 100644 index 00000000..b909533e --- /dev/null +++ b/Python/Easy/19.py @@ -0,0 +1,5 @@ +import math + +result = math.exp(1000) +print(result) + diff --git a/Python/Easy/2.py b/Python/Easy/2.py new file mode 100644 index 00000000..6798f893 --- /dev/null +++ b/Python/Easy/2.py @@ -0,0 +1,5 @@ +result = (5 + 3 * (2 + 4) + +value = (10 + 4 * (3 + 2 +calculation = ((6 * 4) + (7 * 2)) +print(calculation+value) diff --git a/Python/Easy/20.py b/Python/Easy/20.py new file mode 100644 index 00000000..c9ed0c2d --- /dev/null +++ b/Python/Easy/20.py @@ -0,0 +1,5 @@ +def print_elements(elements): + for element in elements: + print(element) + +print_elements(123) diff --git a/Python/Easy/21.py b/Python/Easy/21.py new file mode 100644 index 00000000..229915e5 --- /dev/null +++ b/Python/Easy/21.py @@ -0,0 +1,2 @@ +file_path = "C:\Users\Name\Documents\File.txt" + diff --git a/Python/Easy/22.py b/Python/Easy/22.py new file mode 100644 index 00000000..b4bcaa77 --- /dev/null +++ b/Python/Easy/22.py @@ -0,0 +1,8 @@ +import threading + +def thread_function(): + pass + +thread = threading.Thread(target=thread_function) +thread.start() +thread.start() \ No newline at end of file diff --git a/Python/Easy/23.py b/Python/Easy/23.py new file mode 100644 index 00000000..3691a206 --- /dev/null +++ b/Python/Easy/23.py @@ -0,0 +1 @@ +result = [1, 2, 3] + "string” diff --git a/Python/Easy/24.py b/Python/Easy/24.py new file mode 100644 index 00000000..395f5806 --- /dev/null +++ b/Python/Easy/24.py @@ -0,0 +1 @@ + func = lambda x: x+1; print(x) diff --git a/Python/Easy/25.py b/Python/Easy/25.py new file mode 100644 index 00000000..c2913bbf --- /dev/null +++ b/Python/Easy/25.py @@ -0,0 +1,3 @@ +def add(a, b): + return a + b + result = add(1, 2) + add diff --git a/Python/Easy/26.py b/Python/Easy/26.py new file mode 100644 index 00000000..c5bf4741 --- /dev/null +++ b/Python/Easy/26.py @@ -0,0 +1 @@ +my_dict = dict(1, 2) diff --git a/Python/Easy/27.py b/Python/Easy/27.py new file mode 100644 index 00000000..23a26a75 --- /dev/null +++ b/Python/Easy/27.py @@ -0,0 +1,2 @@ +data = [1, 'a', 3] + sorted(data) diff --git a/Python/Easy/28.py b/Python/Easy/28.py new file mode 100644 index 00000000..31549a63 --- /dev/null +++ b/Python/Easy/28.py @@ -0,0 +1,3 @@ + + len = 100 + print(len([1, 2, 3])) diff --git a/Python/Easy/29.py b/Python/Easy/29.py new file mode 100644 index 00000000..28be54b1 --- /dev/null +++ b/Python/Easy/29.py @@ -0,0 +1,3 @@ +my_dict = {'a': 1, 'b': 2} + for key in my_dict.keys(): + my_dict.pop(key) diff --git a/Python/Easy/3.py b/Python/Easy/3.py new file mode 100644 index 00000000..b6364ba9 --- /dev/null +++ b/Python/Easy/3.py @@ -0,0 +1,10 @@ +def greet(): + print("Hello, world!") + +def add(a, b): + return a + b + +class Car: + def __init__(self, make, model): + self.make = make + self.model = model diff --git a/Python/Easy/30.py b/Python/Easy/30.py new file mode 100644 index 00000000..098f08db --- /dev/null +++ b/Python/Easy/30.py @@ -0,0 +1,2 @@ + s = "abc" + s[0] = 'A' diff --git a/Python/Easy/31.py b/Python/Easy/31.py new file mode 100644 index 00000000..3e7400b7 --- /dev/null +++ b/Python/Easy/31.py @@ -0,0 +1,2 @@ + s = "3.14" + print(int(s)) diff --git a/Python/Easy/32.py b/Python/Easy/32.py new file mode 100644 index 00000000..1b9b5ba7 --- /dev/null +++ b/Python/Easy/32.py @@ -0,0 +1,10 @@ +my_list = [1, 2, 3, 4, +5, 6, 7 8, 9] +my_dict = { + 'key1': 1, + 'key2': 2, + 'key3': 3, + 'key4': 4 + 'key5': 5 +} + diff --git a/Python/Easy/33.py b/Python/Easy/33.py new file mode 100644 index 00000000..e1ddbd6d --- /dev/null +++ b/Python/Easy/33.py @@ -0,0 +1,3 @@ +pairs = [(1, 2), (3, 4)] + for x, y, z in pairs: + print(x, y, z) diff --git a/Python/Easy/34.py b/Python/Easy/34.py new file mode 100644 index 00000000..f4ca5227 --- /dev/null +++ b/Python/Easy/34.py @@ -0,0 +1,5 @@ +numbers = [1, 2, 3, 4] +for num in numbers + if num % 2 == 0: + print(f"{num} is even") + diff --git a/Python/Easy/35.py b/Python/Easy/35.py new file mode 100644 index 00000000..a4b1c8b5 --- /dev/null +++ b/Python/Easy/35.py @@ -0,0 +1,3 @@ +def multiply(a, b): + result = a * b +print(multiply(5, 3)) diff --git a/Python/Easy/36.py b/Python/Easy/36.py new file mode 100644 index 00000000..9a054362 --- /dev/null +++ b/Python/Easy/36.py @@ -0,0 +1,3 @@ +point = (5, 10, 15) +x, y = point +print(f"x: {x}, y: {y}") diff --git a/Python/Easy/37.py b/Python/Easy/37.py new file mode 100644 index 00000000..2bce4c98 --- /dev/null +++ b/Python/Easy/37.py @@ -0,0 +1,2 @@ +my_list = [1, 2, 3, 4, 5] +print(my_list[5:2]) \ No newline at end of file diff --git a/Python/Easy/38.py b/Python/Easy/38.py new file mode 100644 index 00000000..49543cbe --- /dev/null +++ b/Python/Easy/38.py @@ -0,0 +1,2 @@ +numbers = [1, 2, 3, 4, 5] +print(numbers[5]) diff --git a/Python/Easy/39.py b/Python/Easy/39.py new file mode 100644 index 00000000..bc60d97a --- /dev/null +++ b/Python/Easy/39.py @@ -0,0 +1,3 @@ +Modifying Immutable Objects +my_tuple = (1, 2, 3) +my_tuple[0] = 5 diff --git a/Python/Easy/4.py b/Python/Easy/4.py new file mode 100644 index 00000000..ab9606ee --- /dev/null +++ b/Python/Easy/4.py @@ -0,0 +1,9 @@ +message = ‘py" +print(message) + +title = "Python's "cool" feature" + +description = 'This is a Python "error example' + +sentence = “Hello, Python!” +print(sentence) diff --git a/Python/Easy/40.py b/Python/Easy/40.py new file mode 100644 index 00000000..e180d87f --- /dev/null +++ b/Python/Easy/40.py @@ -0,0 +1,3 @@ +text = """This is a multiline string +quote = 'This is an example of a + diff --git a/Python/Easy/41.py b/Python/Easy/41.py new file mode 100644 index 00000000..32e6ab54 --- /dev/null +++ b/Python/Easy/41.py @@ -0,0 +1,5 @@ +x = 10 +if x > 5: + print("x is greater than 5") +elif x > 8: + print("x is greater than 8") diff --git a/Python/Easy/42.py b/Python/Easy/42.py new file mode 100644 index 00000000..f68933f2 --- /dev/null +++ b/Python/Easy/42.py @@ -0,0 +1,3 @@ +x = 5 +if x == 3 and x == 5: + print("x is 3 or 5") diff --git a/Python/Easy/43.py b/Python/Easy/43.py new file mode 100644 index 00000000..8e9443e1 --- /dev/null +++ b/Python/Easy/43.py @@ -0,0 +1,2 @@ +coordinates = [10, 20] +coordinates[0] = 15 diff --git a/Python/Easy/44.py b/Python/Easy/44.py new file mode 100644 index 00000000..23602ed7 --- /dev/null +++ b/Python/Easy/44.py @@ -0,0 +1,6 @@ +x = 10 +if x > 5: + print("x is greater than 5") +elif x < 5: + print("x is less than 5") +else block. diff --git a/Python/Easy/45.py b/Python/Easy/45.py new file mode 100644 index 00000000..e8c842ab --- /dev/null +++ b/Python/Easy/45.py @@ -0,0 +1,5 @@ +def print_elements(x, y): + print(x, y) + +my_list = [1, 2, 3] +print_elements(*my_list) \ No newline at end of file diff --git a/Python/Easy/46.py b/Python/Easy/46.py new file mode 100644 index 00000000..441fe312 --- /dev/null +++ b/Python/Easy/46.py @@ -0,0 +1,4 @@ +def add(x, y): + return x + y + +add 5, 6 diff --git a/Python/Easy/47.py b/Python/Easy/47.py new file mode 100644 index 00000000..f8561c1b --- /dev/null +++ b/Python/Easy/47.py @@ -0,0 +1 @@ +my_dict = {1: "apple", [2]: "banana"} \ No newline at end of file diff --git a/Python/Easy/48.py b/Python/Easy/48.py new file mode 100644 index 00000000..6e9452e8 --- /dev/null +++ b/Python/Easy/48.py @@ -0,0 +1,4 @@ +def greet(): + return +result = greet() + "Hello" + diff --git a/Python/Easy/49.py b/Python/Easy/49.py new file mode 100644 index 00000000..c6524bd1 --- /dev/null +++ b/Python/Easy/49.py @@ -0,0 +1,5 @@ + for i in range(3): + if i == 1: + break +else: + print("Loop completed") diff --git a/Python/Easy/5.py b/Python/Easy/5.py new file mode 100644 index 00000000..eda45bf6 --- /dev/null +++ b/Python/Easy/5.py @@ -0,0 +1,24 @@ +prnt("Hello, world!") +for i in rang(5): + print(i) + + +pritn("Hello, world!") +for i in rnage(10): + print(i) +my_varaible = 10 +print(my_variable) + +x = 10 +y = 5 +result = x - y + z +if x = 5: + print("x is 5") + +if x > 10: + print("x is greater") +else if x == 10: + print("x is equal") + +del my_function() + diff --git a/Python/Easy/50.py b/Python/Easy/50.py new file mode 100644 index 00000000..7df7764c --- /dev/null +++ b/Python/Easy/50.py @@ -0,0 +1,2 @@ + if 5 > "3": + print("5 is greater") diff --git a/Python/Easy/51.py b/Python/Easy/51.py new file mode 100644 index 00000000..ab8dafa4 --- /dev/null +++ b/Python/Easy/51.py @@ -0,0 +1,8 @@ +class Rectangle: + def __init__(self, width, height): + self.width = width + self.height = height + def area(self): + return self.width * self.height +rect = Rectangle(5, 10) +print(rect.area) diff --git a/Python/Easy/52.py b/Python/Easy/52.py new file mode 100644 index 00000000..24c36060 --- /dev/null +++ b/Python/Easy/52.py @@ -0,0 +1,12 @@ +def read_config(filename): + config = {} + try: + with open(filename, 'r') as file: + for line in file: + key, value = line.strip().split('=') + config[key] = value + except FileNotFoundError: + print('Config file not found') + return config +result = read_config('config.txt') +print(result['nonexistent_key']) \ No newline at end of file diff --git a/Python/Easy/53.py b/Python/Easy/53.py new file mode 100644 index 00000000..6ae9483f --- /dev/null +++ b/Python/Easy/53.py @@ -0,0 +1,9 @@ +class Book: + def __init__(self, title, author: + self.title = title + self.author = author + def __eq__(self, other): + return self.title == other.title and self.author == other.author +book1 = Book('Python Programming' 'John Doe') +book2 = "Python Programming" +print(book1 = book2) \ No newline at end of file diff --git a/Python/Easy/54.py b/Python/Easy/54.py new file mode 100644 index 00000000..c6410839 --- /dev/null +++ b/Python/Easy/54.py @@ -0,0 +1,12 @@ + +def read_csv(filename): + data = [] +try: + with open(filename, 'r') as file: + reader = csv.reader(file) + for row in reader: + data.append(row) +except FileNotFoundError: + print('CSV file not found') + return +result = read_csv('data.csv') diff --git a/Python/Easy/55.py b/Python/Easy/55.py new file mode 100644 index 00000000..0dbc4ec8 --- /dev/null +++ b/Python/Easy/55.py @@ -0,0 +1,8 @@ +class Rectangle: + def __init__(self, width, height): + self.width = width + self.height = height + def area(self): + return self.width * self.height +rect = Rectangle(5, 10) +print(rect.area(2)) \ No newline at end of file diff --git a/Python/Easy/56.py b/Python/Easy/56.py new file mode 100644 index 00000000..0990327e --- /dev/null +++ b/Python/Easy/56.py @@ -0,0 +1,5 @@ +try: + file = open('file.txt', 'r') + content = file.read() +finally: + file.close() \ No newline at end of file diff --git a/Python/Easy/57.py b/Python/Easy/57.py new file mode 100644 index 00000000..77a191c5 --- /dev/null +++ b/Python/Easy/57.py @@ -0,0 +1,7 @@ +class Circle: + def __init__(self, radius): + self.radius = radius + def area(self): + return 3.14 * self.radius ** 2 +circle = Circle(7) +print(circle.radius()) \ No newline at end of file diff --git a/Python/Easy/58.py b/Python/Easy/58.py new file mode 100644 index 00000000..18a63b61 --- /dev/null +++ b/Python/Easy/58.py @@ -0,0 +1,8 @@ +def read_lines(filename): +try: + with open(filename, 'r') as file: + lines = file.readlines() +except FileNotFoundError: + print('File not found') + return lines +result = read_lines('file.txt') \ No newline at end of file diff --git a/Python/Easy/59.py b/Python/Easy/59.py new file mode 100644 index 00000000..34c54fbe --- /dev/null +++ b/Python/Easy/59.py @@ -0,0 +1,15 @@ +class BankAccount: + def __init__(self, owner, balance): + self.owner = owner + self.balance = balance + def deposit(self, amount): + self.balance += amount + def withdraw(self, amount): + if self.balance >= amount: + self.balance -= amount + else: + print('Insufficient funds') +account = BankAccount('Alice', 1000) +account.deposit(500) +account.withdraw(200) +print(account.balance()) diff --git a/Python/Easy/6.py b/Python/Easy/6.py new file mode 100644 index 00000000..4e8ca90c --- /dev/null +++ b/Python/Easy/6.py @@ -0,0 +1,13 @@ +funtion greet(): + print("Hello") +def greet: + print("Hello") + +def funtion greet(): + print("Hello") + +def greet: + print("Hello") + +def greet(): + print("Hello") diff --git a/Python/Easy/60.py b/Python/Easy/60.py new file mode 100644 index 00000000..389adc9e --- /dev/null +++ b/Python/Easy/60.py @@ -0,0 +1,8 @@ +try: + result = 10 / 0 +except ZeroDivisionError: + print('Division by zero') +else: + print('No error') +finally: + print('Done') \ No newline at end of file diff --git a/Python/Easy/61.py b/Python/Easy/61.py new file mode 100644 index 00000000..f4a49d0e --- /dev/null +++ b/Python/Easy/61.py @@ -0,0 +1,9 @@ +class Employee: + def __init__(self, name, salary): + self.name = name + self.salary = salary + def give_raise(self, amount): + self.salary += amount +employee = Employee('John', 50000) +employee.give_raise(5000) +print(employee.salary + 1000) diff --git a/Python/Easy/62.py b/Python/Easy/62.py new file mode 100644 index 00000000..14d0bbfb --- /dev/null +++ b/Python/Easy/62.py @@ -0,0 +1,5 @@ +try + file = open('file.txt', 'r') + content = file.read() +finally + file.close() diff --git a/Python/Easy/63.py b/Python/Easy/63.py new file mode 100644 index 00000000..3e77df02 --- /dev/null +++ b/Python/Easy/63.py @@ -0,0 +1,9 @@ +try: + file = open('file.txt', 'r') + content = file.read() +except FileNotFoundError: + print('File not found') +else: + print('File read successfully') +finally: + file.close() \ No newline at end of file diff --git a/Python/Easy/64.py b/Python/Easy/64.py new file mode 100644 index 00000000..a39e26d2 --- /dev/null +++ b/Python/Easy/64.py @@ -0,0 +1,8 @@ +class Student: + def __init__(self, name, grade): + self.name = name + self.grade = grade + def __str__(self): + return f'{self.name} ({self.grade})' +student = Student('Alice', 90) +print(student.__str__()) diff --git a/Python/Easy/65.py b/Python/Easy/65.py new file mode 100644 index 00000000..4a94163d --- /dev/null +++ b/Python/Easy/65.py @@ -0,0 +1,12 @@ +def read_config(filename): + config = {} + try: + with open(filename, 'r') as file: + for line in file: + key, value = line.strip().split('=') + config[key] = value + except FileNotFoundError: + print('Config file not found') + return config +result = read_config('config.txt') +print(result['nonexistent_key']) diff --git a/Python/Easy/66.py b/Python/Easy/66.py new file mode 100644 index 00000000..fe49b07e --- /dev/null +++ b/Python/Easy/66.py @@ -0,0 +1,9 @@ +class Book: + def __init__(self, title, author): + self.title = title + self.author = author + def __eq__(self, other): + return self.title == other.title and self.author == other.author +book1 = Book('Python Programming', 'John Doe') +book2 = "Python Programming" +print(book1 == book2) \ No newline at end of file diff --git a/Python/Easy/67.py b/Python/Easy/67.py new file mode 100644 index 00000000..b9b454ae --- /dev/null +++ b/Python/Easy/67.py @@ -0,0 +1,10 @@ +import pandas as pd + +def read_csv(filename) + try: + data = pd.read_csv(filename + return data + except FileNotFoundError + print('CSV file not found' + +result = read_csv('data.csv' diff --git a/Python/Easy/68.py b/Python/Easy/68.py new file mode 100644 index 00000000..a31691bc --- /dev/null +++ b/Python/Easy/68.py @@ -0,0 +1,5 @@ +try: + file = open('file.txt''r') + content = fileread() +finally + file.close() \ No newline at end of file diff --git a/Python/Easy/69.py b/Python/Easy/69.py new file mode 100644 index 00000000..4037d24c --- /dev/null +++ b/Python/Easy/69.py @@ -0,0 +1,9 @@ +class Circle: + def __init__(self, radius): + self.radius = radius + + def area(self): + return 3.14 * self.radius ** 2 + +circle = Circle(7) +print(circle.area \ No newline at end of file diff --git a/Python/Easy/7.py b/Python/Easy/7.py new file mode 100644 index 00000000..4f42bfab --- /dev/null +++ b/Python/Easy/7.py @@ -0,0 +1,19 @@ +None = "some_value" +if None == "some_value": + print("This shouldn't work, None is a keyword!") +True = 1 +if True: + print("This will cause an error because 'True' is a reserved keyword.") + +def for(x): + return x * 2 + +result = for(5) +print(result) + +if return > 5: + print("You can't use 'return' as a variable name!") + +class = "AdvancedPython" +print("This won't work because 'class' is a reserved keyword in Python.") + diff --git a/Python/Easy/70.py b/Python/Easy/70.py new file mode 100644 index 00000000..833aebb6 --- /dev/null +++ b/Python/Easy/70.py @@ -0,0 +1,10 @@ +class Rectangle: + def __init__(self, width, height): + self.width = width + self.height = height + + def area(self): + return self.width * self.height + +rect = Rectangle(5, 10) +print(rect.area(2)) \ No newline at end of file diff --git a/Python/Easy/71.py b/Python/Easy/71.py new file mode 100644 index 00000000..65b041a5 --- /dev/null +++ b/Python/Easy/71.py @@ -0,0 +1,9 @@ +def read_lines(filename): +try: + with open(filename, 'r') as file: + lines = file.readlines() + except FileNotFoundError: + print('File not found') + return lines + +result = read_lines('file.txt') \ No newline at end of file diff --git a/Python/Easy/72.py b/Python/Easy/72.py new file mode 100644 index 00000000..bbaf9c01 --- /dev/null +++ b/Python/Easy/72.py @@ -0,0 +1,18 @@ +class BankAccount: + def __init__(self, owner, balance): + self.owner = owner + self.balance = balance + + def deposit(self, amount): + self.balance += amount + + def withdraw(self, amount): + if self.balance >= amount: + self.balance -= amount + else: + print('Insufficient funds') + +account = BankAccount('Alice', 1000) +account.deposit(500) +account.withdraw(200) +print(account.balance()) \ No newline at end of file diff --git a/Python/Easy/73.py b/Python/Easy/73.py new file mode 100644 index 00000000..bb7e9973 --- /dev/null +++ b/Python/Easy/73.py @@ -0,0 +1,7 @@ +class Circle: + def __init__(self, radius): + self.radius = radius + def area(self): + return 3.14 * self.radius ** 2 +circle = Circle(7) +print(circle.area) \ No newline at end of file diff --git a/Python/Easy/74.py b/Python/Easy/74.py new file mode 100644 index 00000000..cc72accc --- /dev/null +++ b/Python/Easy/74.py @@ -0,0 +1,8 @@ +try: + result = 10 / 0 +except ZeroDivisionError: + print('Division by zero') +else: + print('No error') +finally: + print('Done' \ No newline at end of file diff --git a/Python/Easy/75.py b/Python/Easy/75.py new file mode 100644 index 00000000..7155cca9 --- /dev/null +++ b/Python/Easy/75.py @@ -0,0 +1,9 @@ +try: + file = open('file.txt', 'r') + content = file.read() +except FileNotFoundError: + print('File not found') +else: + print('File read successfully') +finally: + file.close() \ No newline at end of file diff --git a/Python/Easy/76.py b/Python/Easy/76.py new file mode 100644 index 00000000..5a3ecc58 --- /dev/null +++ b/Python/Easy/76.py @@ -0,0 +1,14 @@ +import csv + +def read_csv(filename): + data = [] + try: + with open(filename, 'r') as file: + reader = csv.reader(file) + for row in reader: + data.append(row) + except FileNotFoundError: + print('CSV file not found') + return data + +result = read_csv('data.csv') diff --git a/Python/Easy/77.py b/Python/Easy/77.py new file mode 100644 index 00000000..1d0e7e3a --- /dev/null +++ b/Python/Easy/77.py @@ -0,0 +1,4 @@ +def check_positive(number): + if number > 0 + print("The number is positive") +check_positive(5) \ No newline at end of file diff --git a/Python/Easy/78.py b/Python/Easy/78.py new file mode 100644 index 00000000..31120904 --- /dev/null +++ b/Python/Easy/78.py @@ -0,0 +1,5 @@ +def read_file(filename): + with open(filename, 'r' + content = file.read() + print(content) +read_file('example.txt') \ No newline at end of file diff --git a/Python/Easy/79.py b/Python/Easy/79.py new file mode 100644 index 00000000..b56b8d92 --- /dev/null +++ b/Python/Easy/79.py @@ -0,0 +1,9 @@ +def calculate_sum(a, b + result = a + b + if result > 10 + print("Result is greater than 10" + else + print("Result is 10 or less" + return result + +sum_value = calculate_sum(5, 7 diff --git a/Python/Easy/8.py b/Python/Easy/8.py new file mode 100644 index 00000000..4a2db9e2 --- /dev/null +++ b/Python/Easy/8.py @@ -0,0 +1,9 @@ +if x = 5: + print("x is 5") +if x == 5: + x = 10 + print("x is now 10") + +x = 5 +if x = 5: + print("x is 5") diff --git a/Python/Easy/80.py b/Python/Easy/80.py new file mode 100644 index 00000000..eb97a1c8 --- /dev/null +++ b/Python/Easy/80.py @@ -0,0 +1,6 @@ +class Dog: + def bark(): + print("Woof!") + +dog = Dog() +dog.bark() \ No newline at end of file diff --git a/Python/Easy/81.py b/Python/Easy/81.py new file mode 100644 index 00000000..c732195a --- /dev/null +++ b/Python/Easy/81.py @@ -0,0 +1,2 @@ +person = {'name': 'John','age': 30,'city': 'New York''country': 'USA'} +print(person) \ No newline at end of file diff --git a/Python/Easy/82.py b/Python/Easy/82.py new file mode 100644 index 00000000..1c47d304 --- /dev/null +++ b/Python/Easy/82.py @@ -0,0 +1,4 @@ +counter = 5 +while counter > 0 + print(counter) + counter -= 1 \ No newline at end of file diff --git a/Python/Easy/83.py b/Python/Easy/83.py new file mode 100644 index 00000000..852ba8ff --- /dev/null +++ b/Python/Easy/83.py @@ -0,0 +1,3 @@ +def greet(name) + print(f"Hello, {name}") +greet("Alice") \ No newline at end of file diff --git a/Python/Easy/84.py b/Python/Easy/84.py new file mode 100644 index 00000000..630dd80e --- /dev/null +++ b/Python/Easy/84.py @@ -0,0 +1,8 @@ +def read_lines(filename): + try: + with open(filename, 'r') as file: + lines = file.readlines() + except FileNotFoundError: + print('File not found') + return lines +result = read_lines('file.txt') \ No newline at end of file diff --git a/Python/Easy/85.py b/Python/Easy/85.py new file mode 100644 index 00000000..fa74a607 --- /dev/null +++ b/Python/Easy/85.py @@ -0,0 +1,6 @@ +try: + result = 10 / 0 +except ZeroDivisionError: + print('Division by zero') +finally: + print('Done' \ No newline at end of file diff --git a/Python/Easy/86.py b/Python/Easy/86.py new file mode 100644 index 00000000..8488706f --- /dev/null +++ b/Python/Easy/86.py @@ -0,0 +1,10 @@ +class Employee: + def __init__(self, name, salary): + self.name = name + self.salary = salary + def give_raise(self, amount): + self.salary += amount + +employee = Employee('John', 50000) +employee.give_raise(5000) +print(employee.salary()) \ No newline at end of file diff --git a/Python/Easy/87.py b/Python/Easy/87.py new file mode 100644 index 00000000..7155cca9 --- /dev/null +++ b/Python/Easy/87.py @@ -0,0 +1,9 @@ +try: + file = open('file.txt', 'r') + content = file.read() +except FileNotFoundError: + print('File not found') +else: + print('File read successfully') +finally: + file.close() \ No newline at end of file diff --git a/Python/Easy/88.py b/Python/Easy/88.py new file mode 100644 index 00000000..272853f0 --- /dev/null +++ b/Python/Easy/88.py @@ -0,0 +1,7 @@ +class Circle: + def __init__(self, radius): + self.radius = radius +def area(self): +return 3.14 * self.radius ** 2 +circle = Circle(7) +print(circle.area) \ No newline at end of file diff --git a/Python/Easy/89.py b/Python/Easy/89.py new file mode 100644 index 00000000..81cf22d7 --- /dev/null +++ b/Python/Easy/89.py @@ -0,0 +1,8 @@ +class Student: + def __init__(self, name, grade) + self.name = name + self.grade = grade + def __str__(self): + return f'{self.name} ({self.grade}' +student = Student('Alice', 90) +print(student.__str__) \ No newline at end of file diff --git a/Python/Easy/9.py b/Python/Easy/9.py new file mode 100644 index 00000000..f8779947 --- /dev/null +++ b/Python/Easy/9.py @@ -0,0 +1,7 @@ +add = lambda x, y: x + y +print(add(3, 5)) +add = lambda x, y: print(x + y) +add(3, 5) + +add = lambda x, y, : x + y +print(add(3, 5)) diff --git a/Python/Easy/90.py b/Python/Easy/90.py new file mode 100644 index 00000000..a0a909a6 --- /dev/null +++ b/Python/Easy/90.py @@ -0,0 +1,8 @@ +try + result = 10 / 0 +except ZeroDivisionEror + print('Division by zero') +else: + print('No error') +finally + print('Done') \ No newline at end of file diff --git a/Python/Easy/91.py b/Python/Easy/91.py new file mode 100644 index 00000000..12e9278c --- /dev/null +++ b/Python/Easy/91.py @@ -0,0 +1,5 @@ +try + file = open('file.txt', 'r') + content = file.read() +finally + file.close() \ No newline at end of file diff --git a/Python/Easy/92.py b/Python/Easy/92.py new file mode 100644 index 00000000..9e7f8d0f --- /dev/null +++ b/Python/Easy/92.py @@ -0,0 +1,7 @@ +class Circle: + def __init__(self, radius): + self.radius = radius + def area(self): + return 3.14 * self.radius ** 2 +circle = Circle(7) +print(circle.radius()) \ No newline at end of file diff --git a/Python/Easy/93.py b/Python/Easy/93.py new file mode 100644 index 00000000..a4572873 --- /dev/null +++ b/Python/Easy/93.py @@ -0,0 +1,11 @@ +import pandas +def read_csv(filename): + data = [] + try + with open(filename, 'r') as file: + df = pandas.read_csv(file + data = df.values.tolist() + except FileNotFoundError + print('CSV file not found') + return data +result = read_csv('data.csv') \ No newline at end of file diff --git a/Python/Easy/94.py b/Python/Easy/94.py new file mode 100644 index 00000000..b6ad76a6 --- /dev/null +++ b/Python/Easy/94.py @@ -0,0 +1,8 @@ +try + result = 10 / 0 +except ZeroDivisionError: + print('Division by zero) +else + print('No error') +finally: + print(Done) \ No newline at end of file diff --git a/Python/Easy/95.py b/Python/Easy/95.py new file mode 100644 index 00000000..b92f2e2e --- /dev/null +++ b/Python/Easy/95.py @@ -0,0 +1,16 @@ +class BankAccount: + def __init__(self, owner, balance): + self.owner = owner + self.balance = balance + def deposit(self, amount): + self.balance += amount + def withdraw(self, amount): + if self.balance >= amount: + self.balance -= amount + else: + print('Insufficient funds') +account = BankAccount('Alice', 1000) +account.deposit(500) +account.withdraw(200) +print(account.balance()) + diff --git a/Python/Easy/96.py b/Python/Easy/96.py new file mode 100644 index 00000000..1c47d304 --- /dev/null +++ b/Python/Easy/96.py @@ -0,0 +1,4 @@ +counter = 5 +while counter > 0 + print(counter) + counter -= 1 \ No newline at end of file diff --git a/Python/Easy/97.py b/Python/Easy/97.py new file mode 100644 index 00000000..d3010c4e --- /dev/null +++ b/Python/Easy/97.py @@ -0,0 +1,8 @@ +try: + result = 10 / 0 +except ZeroDivisionError: + print('Division by zero') +else: + print('No error') +finally: + print('Done') \ No newline at end of file diff --git a/Python/Easy/98.py b/Python/Easy/98.py new file mode 100644 index 00000000..7d0d3acc --- /dev/null +++ b/Python/Easy/98.py @@ -0,0 +1,9 @@ +class Employee: + def __init__(self, name, salary): + self.name = name + self.salary = salary + def give_raise(self, amount): + self.salary += amount +employee = Employee('John', 50000) +employee.give_raise(5000) +print(employee.salary()) \ No newline at end of file diff --git a/Python/Easy/99.py b/Python/Easy/99.py new file mode 100644 index 00000000..5b636630 --- /dev/null +++ b/Python/Easy/99.py @@ -0,0 +1,9 @@ +try: + file = open('file.txt', 'r') + content = file.read() +except FileNotFoundError: + print('File not found') +else: + print('File read successfully') +finally: + file.close() \ No newline at end of file diff --git a/Python/Easy/temp.txt b/Python/Easy/temp.txt new file mode 100644 index 00000000..3d3bb244 --- /dev/null +++ b/Python/Easy/temp.txt @@ -0,0 +1 @@ +"." diff --git a/Python/Medium/10.py b/Python/Medium/10.py new file mode 100644 index 00000000..08763d2a --- /dev/null +++ b/Python/Medium/10.py @@ -0,0 +1,3 @@ +numbers = [1, 2, 3, 4, 5] +squared = [x** for x in numbers] +print(squared) diff --git a/Python/Medium/100.py b/Python/Medium/100.py new file mode 100644 index 00000000..827e612a --- /dev/null +++ b/Python/Medium/100.py @@ -0,0 +1,13 @@ +def is_even(n): + if n % 2 == 1: + return True + else: + return False + def main(): + number = 4 + result = is_even(number) + if result: + print(f"{number} is even") + else: + print(f"{number} is odd") + main() \ No newline at end of file diff --git a/Python/Medium/101.py b/Python/Medium/101.py new file mode 100644 index 00000000..e549a10c --- /dev/null +++ b/Python/Medium/101.py @@ -0,0 +1,5 @@ +if 5 < x < y > z: + print("Puzzling condition") + +if a == b != c > d < e: + print("Confusing multiple conditions") diff --git a/Python/Medium/103.py b/Python/Medium/103.py new file mode 100644 index 00000000..d6f802a4 --- /dev/null +++ b/Python/Medium/103.py @@ -0,0 +1,4 @@ +def my_function(x, y): + print(x + y) + +my_function(x = 5, 3) diff --git a/Python/Medium/106.py b/Python/Medium/106.py new file mode 100644 index 00000000..118f2178 --- /dev/null +++ b/Python/Medium/106.py @@ -0,0 +1,2 @@ +a = 5, b = 10, c = 15 +print(a, b, c) diff --git a/Python/Medium/107.py b/Python/Medium/107.py new file mode 100644 index 00000000..a660e01b --- /dev/null +++ b/Python/Medium/107.py @@ -0,0 +1,19 @@ +def check_numbers(numbers): + for num in numbers: + if num % 2 == 0: + print(f"{num} is even") + return num * 2 + else: + return num * 3 + print(f"{num} is odd") + +result = check_numbers([1, 2, 3, 4]) +print(result) + +def find_number(numbers): + for i in numbers: + if i == 5: + return i * 2 + else: + print(i) + return i + 3 diff --git a/Python/Medium/11.py b/Python/Medium/11.py new file mode 100644 index 00000000..4a754e82 --- /dev/null +++ b/Python/Medium/11.py @@ -0,0 +1,4 @@ +try + result = 10 / 0 +except (ZeroDivisionError) + print("Error occurred") diff --git a/Python/Medium/110.py b/Python/Medium/110.py new file mode 100644 index 00000000..c4a8c872 --- /dev/null +++ b/Python/Medium/110.py @@ -0,0 +1,3 @@ +def add(a, b): + return a + b + result = add(1, 2) + add diff --git a/Python/Medium/114.py b/Python/Medium/114.py new file mode 100644 index 00000000..2ead61f0 --- /dev/null +++ b/Python/Medium/114.py @@ -0,0 +1,3 @@ + s = "hello world" + result = s.split(" ") + Result = s.split("") diff --git a/Python/Medium/118.py b/Python/Medium/118.py new file mode 100644 index 00000000..9bcad4bf --- /dev/null +++ b/Python/Medium/118.py @@ -0,0 +1,4 @@ +name = "John" +lastname = "Wick" +age = 25 +print("Name: " + name + lastname ", Age: " + age "") diff --git a/Python/Medium/12.py b/Python/Medium/12.py new file mode 100644 index 00000000..094483e1 --- /dev/null +++ b/Python/Medium/12.py @@ -0,0 +1,3 @@ +def greet(*args, **kwargs): + print("Hello, " + args + " " + kwargs) +greet("John", last_name="Doe") diff --git a/Python/Medium/121.py b/Python/Medium/121.py new file mode 100644 index 00000000..bf47758d --- /dev/null +++ b/Python/Medium/121.py @@ -0,0 +1,18 @@ +message = ‘py" +print(message) + +title = "Python's "cool" feature" + +description = 'This is a Python "error example' + +sentence = “Hello, Python!” + + def add(self, a, b): + return a + b + + def add(sprint(sentence) +elf, a): + return a + 1 +class Calculator: +calc = Calculator() +print(calc.add(5, 3)) \ No newline at end of file diff --git a/Python/Medium/124.py b/Python/Medium/124.py new file mode 100644 index 00000000..5feff332 --- /dev/null +++ b/Python/Medium/124.py @@ -0,0 +1,31 @@ +None = "some_value" +if None == "some_value": + print("This shouldn't work, None is a keyword!") + +True = 1 +if True: + print("This will cause an error because 'True' is a reserved keyword.") + +def for(x): + return x * 2 + +result = for(5) +print(result) + +return = 10 +if return > 5: + print("You can't use 'return' as a variable name!") + + +class = "AdvancedPython" +print("This won't work because 'class' is a reserved keyword in Python.") + + def add(self, a, b): + return a + b + + def add(sprint(sentence) +elf, a): + return a + 1 +class Calculator: +calc = Calculator() +print(calc.add(5, 3)) diff --git a/Python/Medium/130.py b/Python/Medium/130.py new file mode 100644 index 00000000..8da31ae0 --- /dev/null +++ b/Python/Medium/130.py @@ -0,0 +1,8 @@ +def add_numbers(a, b) + result = a + b + +num1 = 5 +num2 = 10 + +print(add_numbers(num1, num2)) + diff --git a/Python/Medium/132.py b/Python/Medium/132.py new file mode 100644 index 00000000..51f69870 --- /dev/null +++ b/Python/Medium/132.py @@ -0,0 +1,2 @@ +Import numpy: +print(math.trunc(5.677) \ No newline at end of file diff --git a/Python/Medium/133.py b/Python/Medium/133.py new file mode 100644 index 00000000..4f2d90b5 --- /dev/null +++ b/Python/Medium/133.py @@ -0,0 +1,21 @@ +class Shape: + def area(self): + return "Calculating area..." + +class Circle(Shape): + + def area(self, radius): + def add(self, a, b): + return a + b + + def add(sprint(sentence) +elf, a): + return a + 1 +class Calculator: +calc = Calculator() +print(calc.add(5, 3)) +shape = Shape() +circle = Circle() + +print(shape.area()) +print(circle.area()) diff --git a/Python/Medium/136.py b/Python/Medium/136.py new file mode 100644 index 00000000..794b01e9 --- /dev/null +++ b/Python/Medium/136.py @@ -0,0 +1,2 @@ +numbers = [1, 2, 3, 4, 5] +print(numbers[5]) diff --git a/Python/Medium/142.py b/Python/Medium/142.py new file mode 100644 index 00000000..64aeff8c --- /dev/null +++ b/Python/Medium/142.py @@ -0,0 +1,3 @@ +def add(a, b): +sum = a + b + return sum diff --git a/Python/Medium/143.py b/Python/Medium/143.py new file mode 100644 index 00000000..419fab52 --- /dev/null +++ b/Python/Medium/143.py @@ -0,0 +1,5 @@ +x = 5 +if x < 10: + print("x is less than 10") +else x > 10: + print("x is greater than 10") diff --git a/Python/Medium/144.py b/Python/Medium/144.py new file mode 100644 index 00000000..e66e91d3 --- /dev/null +++ b/Python/Medium/144.py @@ -0,0 +1,4 @@ +counter = 0 +while counter = 5: + print(counter) + counter += 1 diff --git a/Python/Medium/147.py b/Python/Medium/147.py new file mode 100644 index 00000000..eb76aaf9 --- /dev/null +++ b/Python/Medium/147.py @@ -0,0 +1,2 @@ +x = 10 +return x diff --git a/Python/Medium/148.py b/Python/Medium/148.py new file mode 100644 index 00000000..76ae0477 --- /dev/null +++ b/Python/Medium/148.py @@ -0,0 +1,4 @@ +try: + print(1 / 0) +except ZeroDivisionError + print("Can't divide by zero") diff --git a/Python/Medium/150.py b/Python/Medium/150.py new file mode 100644 index 00000000..b62480c7 --- /dev/null +++ b/Python/Medium/150.py @@ -0,0 +1,18 @@ +class Dog: + def __init__(name): + self.name = name + + def bark(): + print(self.name + " is barking") + +my_dog = Dog("Buddy") +my_dog.bark() +def add(self, a, b): + return a + b + + def add(sprint(sentence) +elf, a): + return a + 1 +class Calculator: +calc = Calculator() +print(calc.add(5, 3)) diff --git a/Python/Medium/17.py b/Python/Medium/17.py new file mode 100644 index 00000000..4a694033 --- /dev/null +++ b/Python/Medium/17.py @@ -0,0 +1,2 @@ +Import math: +print(math.trunc(5.677) diff --git a/Python/Medium/18.py b/Python/Medium/18.py new file mode 100644 index 00000000..824a011d --- /dev/null +++ b/Python/Medium/18.py @@ -0,0 +1,3 @@ +for i in range(5) +break +print(i) diff --git a/Python/Medium/2.py b/Python/Medium/2.py new file mode 100644 index 00000000..96f22e93 --- /dev/null +++ b/Python/Medium/2.py @@ -0,0 +1,2 @@ +x = 10 +print(len(x)) diff --git a/Python/Medium/22.py b/Python/Medium/22.py new file mode 100644 index 00000000..08b50a84 --- /dev/null +++ b/Python/Medium/22.py @@ -0,0 +1,8 @@ +a=3 +b=4 +print(a+b+c) + +x = 5 +y = z + +print(x + y) diff --git a/Python/Medium/23.py b/Python/Medium/23.py new file mode 100644 index 00000000..3be4031f --- /dev/null +++ b/Python/Medium/23.py @@ -0,0 +1,8 @@ +n=12 +If n%2=0: + print(‘even number’) + +num = 15 + +if num = 10: + print("Number is 10") diff --git a/Python/Medium/26.py b/Python/Medium/26.py new file mode 100644 index 00000000..89f4bcd7 --- /dev/null +++ b/Python/Medium/26.py @@ -0,0 +1,10 @@ +def multiply: + Return a*b +a=int(input(‘enter a num’)) +b=int(input(‘enter another number’)) + +def square(num): + return num * num + + +square diff --git a/Python/Medium/27.py b/Python/Medium/27.py new file mode 100644 index 00000000..bf3b6b58 --- /dev/null +++ b/Python/Medium/27.py @@ -0,0 +1,9 @@ +age = 25 +message = "I am " + age + " years old." +print(message) + +age = "25" + +message = "I am " + age + " years old." + +print(message) diff --git a/Python/Medium/29.py b/Python/Medium/29.py new file mode 100644 index 00000000..2724d901 --- /dev/null +++ b/Python/Medium/29.py @@ -0,0 +1,5 @@ +def infinite_recursion(n): + return infinite_recursion(n + 1) + +result = infinite_recursion(0) +print(result) diff --git a/Python/Medium/3.py b/Python/Medium/3.py new file mode 100644 index 00000000..2b6e9d84 --- /dev/null +++ b/Python/Medium/3.py @@ -0,0 +1,3 @@ +name = "John" +age = 25 +print("Name: " + name + ", Age: " + age) diff --git a/Python/Medium/32.py b/Python/Medium/32.py new file mode 100644 index 00000000..08a5f6b8 --- /dev/null +++ b/Python/Medium/32.py @@ -0,0 +1,7 @@ +import sys + +sys.setrecursionlimit(10) +def recursive_function(): + recursive_function() + +recursive_function() diff --git a/Python/Medium/33.py b/Python/Medium/33.py new file mode 100644 index 00000000..08a5f6b8 --- /dev/null +++ b/Python/Medium/33.py @@ -0,0 +1,7 @@ +import sys + +sys.setrecursionlimit(10) +def recursive_function(): + recursive_function() + +recursive_function() diff --git a/Python/Medium/37.py b/Python/Medium/37.py new file mode 100644 index 00000000..5ffb9a4f --- /dev/null +++ b/Python/Medium/37.py @@ -0,0 +1,4 @@ +def add(a, b): + return a + b + result = add(1, 2) + add + diff --git a/Python/Medium/40.py b/Python/Medium/40.py new file mode 100644 index 00000000..561415e8 --- /dev/null +++ b/Python/Medium/40.py @@ -0,0 +1,2 @@ +my_dict = {'a': 1, 'b': 2} +print(my_dict['c']) diff --git a/Python/Medium/41.py b/Python/Medium/41.py new file mode 100644 index 00000000..7f8a37cf --- /dev/null +++ b/Python/Medium/41.py @@ -0,0 +1,4 @@ +s = "hello world" +result = s.split(" ") +Result = s.split("") + diff --git a/Python/Medium/42.py b/Python/Medium/42.py new file mode 100644 index 00000000..fc1bdacb --- /dev/null +++ b/Python/Medium/42.py @@ -0,0 +1 @@ +r = range(3, 10, 0) diff --git a/Python/Medium/44.py b/Python/Medium/44.py new file mode 100644 index 00000000..356df61a --- /dev/null +++ b/Python/Medium/44.py @@ -0,0 +1,14 @@ +def calculate_sum(): + sum = 0 + + + numbers = [1, 2, 3, 4] + total = sum(numbers) + print("The sum of the numbers is:", total) + + + more_numbers = [10, 20, 30] + result = sum(more_numbers) + print("The result is:", result) + +calculate_sum() diff --git a/Python/Medium/48.py b/Python/Medium/48.py new file mode 100644 index 00000000..d8cf07f6 --- /dev/null +++ b/Python/Medium/48.py @@ -0,0 +1,7 @@ +class A: + def method(): + print("Hello") + +a = A() +a.method() + diff --git a/Python/Medium/50.py b/Python/Medium/50.py new file mode 100644 index 00000000..d8340cfa --- /dev/null +++ b/Python/Medium/50.py @@ -0,0 +1,21 @@ +def increment_example(): + x = 10 + + + y = x++ + + + print("The value of y is:", y) + + + print("The value of x after incrementing is:", x) + +increment_example() + + +a = 7 +b = a++ + + +print("The value of b is:", b) +print("The value of a after incrementing is:", a) diff --git a/Python/Medium/51.py b/Python/Medium/51.py new file mode 100644 index 00000000..f81fc34e --- /dev/null +++ b/Python/Medium/51.py @@ -0,0 +1,11 @@ +def factorial(n): + if n == 0: + return 1 + return n * factorial(n - 1) + def main(): + try: + result = factorial(-5) + print(f"Factorial: {result}") + except RecursionError as e: + print(f"RecursionError: {e}") + main() \ No newline at end of file diff --git a/Python/Medium/52.py b/Python/Medium/52.py new file mode 100644 index 00000000..fb8d2ebc --- /dev/null +++ b/Python/Medium/52.py @@ -0,0 +1,9 @@ +def append_to_list(item, lst=[]): + lst.append(item) + return lst + def main(): + list1 = append_to_list(1) + print(f"List after first append: {list1}") + list2 = append_to_list(2) + print(f"List after second append: {list2}") + main() \ No newline at end of file diff --git a/Python/Medium/53.py b/Python/Medium/53.py new file mode 100644 index 00000000..888f7781 --- /dev/null +++ b/Python/Medium/53.py @@ -0,0 +1,13 @@ + def calculate_average(lst): + total = 0 + for num in lst: + total += num + return total / len(lst) + def main(): + numbers = [] + try: + avg = calculate_average(numbers) + print(f"Average: {avg}") +except ZeroDivisionError as e: + print(f"ZeroDivisionError: {e}") + main() \ No newline at end of file diff --git a/Python/Medium/54.py b/Python/Medium/54.py new file mode 100644 index 00000000..f41c2c07 --- /dev/null +++ b/Python/Medium/54.py @@ -0,0 +1,11 @@ + def find_number(lst, target): + for num in lst: + if num == target: + print(f"Found {target}") + break + else: + print(f"{target} not found in the list") + def main(): + numbers = [1, 2, 3, 4, 5] + find_number(numbers, 6) + main() \ No newline at end of file diff --git a/Python/Medium/55.py b/Python/Medium/55.py new file mode 100644 index 00000000..bf4b1690 --- /dev/null +++ b/Python/Medium/55.py @@ -0,0 +1,13 @@ + def concatenate_strings(lst): + result = "" + for item in lst: + result += item + return result + def main(): + items = ["Hello", " ", 123, "World!"] + try: + result = concatenate_strings(items) + print(result) + except TypeError as e: + print(f"TypeError: {e}") + main() \ No newline at end of file diff --git a/Python/Medium/56.py b/Python/Medium/56.py new file mode 100644 index 00000000..12ed46e7 --- /dev/null +++ b/Python/Medium/56.py @@ -0,0 +1,12 @@ +def sort_list(lst): + try: + lst.sort() +return lst + except TypeError as e: + print(f"TypeError: {e}") + def main(): + items = [5, "banana", 3, "apple"] + sorted_items = sort_list(items) + if sorted_items: + print(f"Sorted items: {sorted_items}") + main() \ No newline at end of file diff --git a/Python/Medium/57.py b/Python/Medium/57.py new file mode 100644 index 00000000..4a6c141c --- /dev/null +++ b/Python/Medium/57.py @@ -0,0 +1,11 @@ +def recursive_sum(n): + if n == 0: + return 0 + return n + recursive_sum(n - 1) + def main(): + try: + result = recursive_sum(-5) + print(f"Sum: {result}") + except RecursionError as e: + print(f"RecursionError: {e}") + main() \ No newline at end of file diff --git a/Python/Medium/58.py b/Python/Medium/58.py new file mode 100644 index 00000000..391ca64a --- /dev/null +++ b/Python/Medium/58.py @@ -0,0 +1,11 @@ + def access_nested_list(nested_list, outer_index, inner_index): + try: + return nested_list[outer_index][inner_index] + except IndexError as e: + print(f"IndexError: {e}") + def main(): + nested_list = [[1, 2, 3], [4, 5], [6]] + result = access_nested_list(nested_list, 1, 5) + if result is not None: + print(f"Accessed value: {result}") + main() \ No newline at end of file diff --git a/Python/Medium/59.py b/Python/Medium/59.py new file mode 100644 index 00000000..e5adf202 --- /dev/null +++ b/Python/Medium/59.py @@ -0,0 +1,15 @@ +def factorial(n): + if n < 0: + return "Factorial not defined for negative numbers" + result = 1 + for i in range(n): + result *= i + return result + def main(): + try: + value = 5 + result = factorial(value) + print(f"Factorial of {value} is {result}") + except Exception as e: + print(f"Error: {e}") + main() \ No newline at end of file diff --git a/Python/Medium/60.py b/Python/Medium/60.py new file mode 100644 index 00000000..0e276da5 --- /dev/null +++ b/Python/Medium/60.py @@ -0,0 +1,13 @@ +def filter_positive_numbers(lst): + positive_numbers = [] + for num in lst: + if num > 0: + positive_numbers.append(num) + elif num == 0: + print("Zero is neither positive nor negative") + return positive_numbers + def main(): + numbers = [1, -2, 3, 0, -5, 4] + filtered = filter_positive_numbers(numbers) + print(f"Positive numbers: {filtered}") + main() \ No newline at end of file diff --git a/Python/Medium/61.py b/Python/Medium/61.py new file mode 100644 index 00000000..bd2cef5f --- /dev/null +++ b/Python/Medium/61.py @@ -0,0 +1,14 @@ +def is_prime(n): + if n < 2: + return False + for i in range(2, n // 2): + if n % i == 0: + return False + return True + def main(): + number = 15 +if is_prime(number): + print(f"{number} is a prime number") + else: + print(f"{number} is not a prime number") + main() \ No newline at end of file diff --git a/Python/Medium/62.py b/Python/Medium/62.py new file mode 100644 index 00000000..fadd37ce --- /dev/null +++ b/Python/Medium/62.py @@ -0,0 +1,11 @@ +def get_element(lst, index): + try: + return lst[index] + except IndexError as e: + print(f"IndexError: {e}") + def main(): + numbers = [1, 2, 3] + result = get_element(numbers, 5) + if result is not None: + print(f"Element at index 5: {result}") + main() \ No newline at end of file diff --git a/Python/Medium/63.py b/Python/Medium/63.py new file mode 100644 index 00000000..95f1a5b8 --- /dev/null +++ b/Python/Medium/63.py @@ -0,0 +1,13 @@ +def is_in_range(n, start, end): + if n >= start or n <= end: + return True + return False + def main(): + number = 5 + start = 1 + end = 10 + if is_in_range(number, start, end): + print(f"{number} is within the range [{start}, {end}]") + else: + print(f"{number} is not within the range [{start}, {end}]") + main() \ No newline at end of file diff --git a/Python/Medium/64.py b/Python/Medium/64.py new file mode 100644 index 00000000..cd7c65d7 --- /dev/null +++ b/Python/Medium/64.py @@ -0,0 +1,8 @@ +try: + result = 10 / 0 + except ZeroDivisionError: + print('Division by zero') + else: + print('No error') + finally: + print('Done') \ No newline at end of file diff --git a/Python/Medium/65.py b/Python/Medium/65.py new file mode 100644 index 00000000..51e48574 --- /dev/null +++ b/Python/Medium/65.py @@ -0,0 +1,9 @@ + class Employee: + def __init__(self, name, salary): + self.name = name + self.salary = salary + def give_raise(self, amount): +self.salary += amount + employee = Employee('John', 50000) + employee.give_raise('5000') + print(employee.salary) \ No newline at end of file diff --git a/Python/Medium/66.py b/Python/Medium/66.py new file mode 100644 index 00000000..c824d6ea --- /dev/null +++ b/Python/Medium/66.py @@ -0,0 +1,9 @@ +try: + file = open('non_existent_file.txt', 'r') + content = file.read() + except FileNotFoundError: + print('File not found') + else: + print('File read successfully') + finally: + file.close() \ No newline at end of file diff --git a/Python/Medium/67.py b/Python/Medium/67.py new file mode 100644 index 00000000..14e7f370 --- /dev/null +++ b/Python/Medium/67.py @@ -0,0 +1,8 @@ +class Student: + def __init__(self, name, grade): + self.name = name + self.grade = grade + def __str__(self): + return f'{self.name} ({self.grade})' + student = Student('Alice', 90) + print(student.__str__()) \ No newline at end of file diff --git a/Python/Medium/68.py b/Python/Medium/68.py new file mode 100644 index 00000000..0050dd75 --- /dev/null +++ b/Python/Medium/68.py @@ -0,0 +1,11 @@ + def read_config(filename): + config = {} + try: + with open(filename, 'r') as file: + for line in file: + key, value = line.strip().split('=') + config[key] = value + except FileNotFoundError: + print('Config file not found') + return config + result = read_config('config.txt') \ No newline at end of file diff --git a/Python/Medium/69.py b/Python/Medium/69.py new file mode 100644 index 00000000..549796e5 --- /dev/null +++ b/Python/Medium/69.py @@ -0,0 +1,12 @@ +class Book: + def __init__(self, title, author): + self.title = title + self.author = author + + def __eq__(self, other): + return self.title == other.title and self.author == other.author + +book1 = Book('Python Programming', 'John Doe') +book2 = "Python Programming" + +print(book1 == book2) diff --git a/Python/Medium/70.py b/Python/Medium/70.py new file mode 100644 index 00000000..2aeaac2c --- /dev/null +++ b/Python/Medium/70.py @@ -0,0 +1,11 @@ +def read_csv(filename): + data = [] + try: + with open(filename, 'r') as file: + reader = csv.reader(file) + for row in reader: + data.append(row) + except FileNotFoundError: + print('CSV file not found') + return data +result = read_csv('data.csv') \ No newline at end of file diff --git a/Python/Medium/71.py b/Python/Medium/71.py new file mode 100644 index 00000000..bdaf693a --- /dev/null +++ b/Python/Medium/71.py @@ -0,0 +1,8 @@ +try: + result = 10 +except ZeroDivisionError: + print('Division by zero') +else: + print('No error, but there was no division either!') +finally: + print('Done') diff --git a/Python/Medium/72.py b/Python/Medium/72.py new file mode 100644 index 00000000..f9457def --- /dev/null +++ b/Python/Medium/72.py @@ -0,0 +1,9 @@ +class Employee: + def __init__(self, name, salary): + self.name = name + self.salary = salary + def give_raise(self, amount): + self.salary += amount +employee = Employee('John', 50000) +employee.give_raise('5000') +print(employee.salary) diff --git a/Python/Medium/73.py b/Python/Medium/73.py new file mode 100644 index 00000000..efab262b --- /dev/null +++ b/Python/Medium/73.py @@ -0,0 +1,10 @@ + def countdown(n): + while n >= 0: + print(n) + n += 1 + def main(): + try: + countdown(5) + except KeyboardInterrupt: + print("Countdown interrupted") +main() \ No newline at end of file diff --git a/Python/Medium/74.py b/Python/Medium/74.py new file mode 100644 index 00000000..ac3e3495 --- /dev/null +++ b/Python/Medium/74.py @@ -0,0 +1,12 @@ + +try: + file = open('non_existent_file.txt', 'r') + content = file.read() +except FileNotFoundError: + print('File not found') + file.close() +else + print('File read successfully') +finally: + if file: + file.close() diff --git a/Python/Medium/75.py b/Python/Medium/75.py new file mode 100644 index 00000000..3b8bc447 --- /dev/null +++ b/Python/Medium/75.py @@ -0,0 +1,8 @@ +class Student: + def __init__(self, name, grade): + self.name = name + self.grade = grade + def __str__(self): + return f'{self.name} ({self.grade})' +student = Student('Alice', 90) +print(student.grade()) diff --git a/Python/Medium/76.py b/Python/Medium/76.py new file mode 100644 index 00000000..b4208ffb --- /dev/null +++ b/Python/Medium/76.py @@ -0,0 +1,12 @@ +def read_config(filename): + config = {} + try: + with open(filename, 'r') as file: + for line in file: + key, value = line.strip().split('=') +ne '=' + config[key] = value + except FileNotFoundError: + print('Config file not found') + return config +result = read_config('config.txt') diff --git a/Python/Medium/77.py b/Python/Medium/77.py new file mode 100644 index 00000000..3ac4e41d --- /dev/null +++ b/Python/Medium/77.py @@ -0,0 +1,11 @@ +class Book: + def __init__(self, title, author): + self.title = title + self.author = author + def __eq__(self, other): + if isinstance(other, Book): + return self.title == other.title and self.author == other.author + return False +book1 = Book('Python Programming', 'John Doe') +book2 = "Python Programming" +print(book1 == book2) diff --git a/Python/Medium/78.py b/Python/Medium/78.py new file mode 100644 index 00000000..2aeaac2c --- /dev/null +++ b/Python/Medium/78.py @@ -0,0 +1,11 @@ +def read_csv(filename): + data = [] + try: + with open(filename, 'r') as file: + reader = csv.reader(file) + for row in reader: + data.append(row) + except FileNotFoundError: + print('CSV file not found') + return data +result = read_csv('data.csv') \ No newline at end of file diff --git a/Python/Medium/79.py b/Python/Medium/79.py new file mode 100644 index 00000000..968cef11 --- /dev/null +++ b/Python/Medium/79.py @@ -0,0 +1,10 @@ +def sum_of_elements(lst): + total = 0 + for i in range(len(lst)): + total += lst[i + 1] + return total +def main(): + numbers = [1, 2, 3, 4] + result = sum_of_elements(numbers) + print(f"Sum: {result}") +main() diff --git a/Python/Medium/80.py b/Python/Medium/80.py new file mode 100644 index 00000000..1032ac76 --- /dev/null +++ b/Python/Medium/80.py @@ -0,0 +1,21 @@ +x = 10 + +def modify_variable(): + x = 5 + def inner_function(): + global x + x += 5 + print(f"Modified inner x: {x}") + + inner_function() + print(f"Modified x in outer function: {x}") + +def another_modify_variable(): + x = 20 + print(f"Another modified x: {x}") + +def main(): + modify_variable() + another_modify_variable() + print(f"Final x: {x}") +main() diff --git a/Python/Medium/81.py b/Python/Medium/81.py new file mode 100644 index 00000000..c808e037 --- /dev/null +++ b/Python/Medium/81.py @@ -0,0 +1,23 @@ +def factorial(n): + if n < 0: + return None + result = 1 + while n >= 1: + result *= n + n += 1 + return result + +def memoized_factorial(n, cache={}): + if n in cache: + return cache[n] + if n == 0 or n == 1: + return 1 + cache[n] = n * memoized_factorial(n - 1) + return cache[n] + +def main(): + number = 5 + print(f"Factorial of {number}: {factorial(number)}") + print(f"Memoized Factorial of {number}: {memoized_factorial(number)}") + print(f"Factorial of -1: {factorial(-1)}") +main() diff --git a/Python/Medium/82.py b/Python/Medium/82.py new file mode 100644 index 00000000..040f7a40 --- /dev/null +++ b/Python/Medium/82.py @@ -0,0 +1,10 @@ +def reverse_string(s): + reversed_s = '' + for i in range(len(s)): + reversed_s += s[i] + return reversed_s +def main(): + string = "hello" + result = reverse_string(string) + print(f"Reversed string: {result}") +main() diff --git a/Python/Medium/83.py b/Python/Medium/83.py new file mode 100644 index 00000000..8c10eb14 --- /dev/null +++ b/Python/Medium/83.py @@ -0,0 +1,7 @@ +def sort_dict_by_values(d): + return sorted(d, key=lambda x: x[1]); +def main(): + my_dict = {'a': 3, 'b': 1, 'c': 2}: + result = sort_dict_by_values(my_dict) + print(f"Sorted dictionary: {result}") +main(); diff --git a/Python/Medium/84.py b/Python/Medium/84.py new file mode 100644 index 00000000..ca153e03 --- /dev/null +++ b/Python/Medium/84.py @@ -0,0 +1,11 @@ + def divide(a, b): + try: + return a / b + except: + print("An error occurred") + return None + def main(): + result = divide(10, 0) + if result is not None: + print(f"Result: {result}") + main() \ No newline at end of file diff --git a/Python/Medium/85.py b/Python/Medium/85.py new file mode 100644 index 00000000..183ebfb2 --- /dev/null +++ b/Python/Medium/85.py @@ -0,0 +1,11 @@ +def find_max(lst): + max_val = lst[0] + for i in range(len(lst)): + if lst[i] < max_val: + max_val = lst[i] + return max_val +def main(): + numbers = [1, 4, 2, 8, 3] + result = find_max(numbers) + print(f"Max value: {result}") +main() \ No newline at end of file diff --git a/Python/Medium/86.py b/Python/Medium/86.py new file mode 100644 index 00000000..464506b3 --- /dev/null +++ b/Python/Medium/86.py @@ -0,0 +1,13 @@ +def check_even_odd(lst): + evens = [] + odds = [] + for n in lst: + if n % 2 == 0: + odds.append(n) + else: + evens.append(n) +def main(): + numbers = [1, 2, 3, 4, 5, 6] + evens, odds = check_even_odd(numbers) + print(f"Evens: {evens}, Odds: {odds}") +main() \ No newline at end of file diff --git a/Python/Medium/87.py b/Python/Medium/87.py new file mode 100644 index 00000000..935115fe --- /dev/null +++ b/Python/Medium/87.py @@ -0,0 +1,12 @@ +def add_matrices(mat1, mat2): + result = [] + for i in range(len(mat1)): + for j in range(len(mat2)): + result.append(mat1[i][j] + mat2[i][j]) + return result +def main(): + matrix1 = [[1, 2], [3, 4]] + matrix2 = [[5, 6], [7, 8]] + result = add_matrices(matrix1, matrix2) + print(f"Matrix sum: {result}") +main() diff --git a/Python/Medium/88.py b/Python/Medium/88.py new file mode 100644 index 00000000..bd7afd23 --- /dev/null +++ b/Python/Medium/88.py @@ -0,0 +1,19 @@ +def merge_sorted_lists(lst1, lst2): + merged = [] + i = j = 0 + while i < len(lst1) and j < len(lst2): + if lst1[i] > lst2[j]: + merged.append(lst1[i]) + i += 1 + else: + merged.append(lst2[j]) + j += 1 + merged += lst1[i:] + merged += lst2[j:] + return merged +def main(): + list1 = [1, 3, 5] + list2 = [2, 4, 6] + result = merge_sorted_lists(list1, list2) + print(f"Merged list: {result}") +main() diff --git a/Python/Medium/89.py b/Python/Medium/89.py new file mode 100644 index 00000000..f789e72a --- /dev/null +++ b/Python/Medium/89.py @@ -0,0 +1,11 @@ +def power(base, exp): + if exp == 0: + return 1 + else: + return base * power(base, exp - 2) +def main(): + base = 2 + exp = 3 + result = power(base, exp) + print(f"{base}^{exp} = {result}") +main() diff --git a/Python/Medium/90.py b/Python/Medium/90.py new file mode 100644 index 00000000..87364450 --- /dev/null +++ b/Python/Medium/90.py @@ -0,0 +1,13 @@ +def is_even(n): + if n % 2 == 1: + return True + else: + return False +def main(): + number = 4 + result = is_even(number) + if result: + print(f"{number} is even") + else: + print(f"{number} is odd") + main() \ No newline at end of file diff --git a/Python/Medium/91.py b/Python/Medium/91.py new file mode 100644 index 00000000..40f34aa0 --- /dev/null +++ b/Python/Medium/91.py @@ -0,0 +1,12 @@ +def get_value(d, key): + try: + return d[key] + except KeyError as e: + print(f"KeyError: {e}") + return None +def main(): + my_dict = {"a": 1, "b": 2} + value = get_value(my_dict, "c") + if value is not None: + print(f"Value for key 'c': {value}") +main() diff --git a/Python/Medium/92.py b/Python/Medium/92.py new file mode 100644 index 00000000..41414d2a --- /dev/null +++ b/Python/Medium/92.py @@ -0,0 +1,9 @@ +try: + file = open('non_existent_file.txt', 'r') + content = file.read() +except FileNotFoundError: + print('File not found') +else: + print('File read successfully') +finally: + file.close() diff --git a/Python/Medium/93.py b/Python/Medium/93.py new file mode 100644 index 00000000..2f48ec83 --- /dev/null +++ b/Python/Medium/93.py @@ -0,0 +1,15 @@ +def fibonacci(n): + if n == 0: + return 0 + elif n == 1: + return 1 + else: + return fibonacci(n - 1) + fibonacci(n - 2) +def main(): +try: +Intermediate Level Code Snippets 18 + result = fibonacci(-3) + print(f"Fibonacci: {result}") + except RecursionError as e: + print(f"RecursionError: {e}") +main() diff --git a/Python/Medium/94.py b/Python/Medium/94.py new file mode 100644 index 00000000..f9457def --- /dev/null +++ b/Python/Medium/94.py @@ -0,0 +1,9 @@ +class Employee: + def __init__(self, name, salary): + self.name = name + self.salary = salary + def give_raise(self, amount): + self.salary += amount +employee = Employee('John', 50000) +employee.give_raise('5000') +print(employee.salary) diff --git a/Python/Medium/95.py b/Python/Medium/95.py new file mode 100644 index 00000000..2eb4319b --- /dev/null +++ b/Python/Medium/95.py @@ -0,0 +1,14 @@ +def filter_strings(lst): + filtered = [] + for x in lst: + try: + if x > 5: + filtered.append(x) + except TypeError as e: + print(f"TypeError: {e}") + return filtered + def main(): + values = ["apple", 10, "banana", 7] + result = filter_strings(values) + print(f"Filtered values: {result}") + main() \ No newline at end of file diff --git a/Python/Medium/96.py b/Python/Medium/96.py new file mode 100644 index 00000000..61a9b882 --- /dev/null +++ b/Python/Medium/96.py @@ -0,0 +1,7 @@ +def sort_dict_by_values(d): + return sorted(d, key=lambda x: x[1]) +def main(): + my_dict = {'a': 3, 'b': 1, 'c': 2} + result = sort_dict_by_values(my_dict) + print(f"Sorted dictionary: {result}") +main() diff --git a/Python/Medium/97.py b/Python/Medium/97.py new file mode 100644 index 00000000..05013e2b --- /dev/null +++ b/Python/Medium/97.py @@ -0,0 +1,14 @@ + def fibonacci(n): + if n == 0: + return 0 + elif n == 1: + return 1 +else: + return fibonacci(n - 1) + fibonacci(n - 2) + def main(): + try: + result = fibonacci(-3) + print(f"Fibonacci: {result}") + except RecursionError as e: + print(f"RecursionError: {e}") + main() \ No newline at end of file diff --git a/Python/Medium/98.py b/Python/Medium/98.py new file mode 100644 index 00000000..1de7cf1a --- /dev/null +++ b/Python/Medium/98.py @@ -0,0 +1,11 @@ +def safe_divide(a, b): + if b == 0: + return "Cannot divide by zero" + return a / b + def main(): + try: + print(safe_divide(10, 0)) + print(safe_divide(0, 0)) + except ZeroDivisionError as e: + print(f"ZeroDivisionError: {e}") + main() \ No newline at end of file diff --git a/Python/Medium/99.py b/Python/Medium/99.py new file mode 100644 index 00000000..6b4ab2f8 --- /dev/null +++ b/Python/Medium/99.py @@ -0,0 +1,12 @@ +def get_value(d, key): + try: + return d[key] + except KeyError as e: + print(f"KeyError: {e}") + return None + def main(): + my_dict = {"a": 1, "b": 2} + value = get_value(my_dict, "c") + if value is not None: + print(f"Value for key 'c': {value}") + main() \ No newline at end of file diff --git a/Python/Medium/temp.txt b/Python/Medium/temp.txt new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/Python/Medium/temp.txt @@ -0,0 +1 @@ +