EduLearn - Online Education Platform

Welcome to EduLearn!

Start learning today with our wide range of courses taught by industry experts. Gain new skills, advance your career, or explore new interests.

Browse Courses

Java data structure practice programs for leetcode

Given two strings needle and haystack, return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.   Example 1: Input: haystack = “sadbutsad”, needle = “sad” Output: 0 Explanation: “sad” occurs at index 0 and 6. The first occurrence is at index 0, so we […]

Java practice programs in data structures

Given a non-empty array of integers nums[], every element appears twice except for one. Find that single one.   Input: nums = [2,2,1] Output: 1 Example 2: Input: nums = [4,1,2,1,2] Output: 4     ——————————— public class Main { public static int SingleNumber(int[] nums)//2,2,1 { int result = 0; for (int num : nums) […]

Java practice programs for leetcode

Given an integer array nums[], rotate the array to the right by k steps, where k is non-negative.   Example 1: Input: nums = [1,2,3,4,5,6,7], k = 3 Output: [5,6,7,1,2,3,4] Explanation: rotate 1 steps to the right: [7,1,2,3,4,5,6] rotate 2 steps to the right: [6,7,1,2,3,4,5] rotate 3 steps to the right: [5,6,7,1,2,3,4]   ————————————————– class […]

Java practice programs for leetcode

Create an interface Printable with a method print(), implement this interface in classes Document and photo   interface Printable { void print(); }   class Document implements Printable { void print() { System.out.println(“Document printed”); } }   class Photo implements Printable { void print() { System.out.println(“Photo printed”); } }   class Main { public static […]

Java code to create rectangle with attributes

Create a class Rectangle with attributes length and width. Use a constructor to initialize values and calculate the area   class Rectangle { int length, width;   Rectangle(int l,int w) { length=l; width=w; }   int area() { return length*width; } } class Main { public static void main(String args[]) { Rectangle r=new Rectangle(10,2); System.out.println(“Area=” […]

Java practice programs to create student details form

Create a student class with name, roll number. Use a constructor to initialize and display the student details     class Student { String name; int rollNo;   Student(String name,int rollNo) { this.name=name; this.rollNo=rollNo; }   void display() { System.out.println(name); System.out.println(rollNo); } } class Main { public static void main(String args[]) { Student s1=new Student(“John”,101); […]

Java code to find student data

Create a student class with attributes name, roll number and marks. create 2 student objects and display their details   class Student { String name; int rollNo; int marks;   void display() { System.out.println(“Name=” +name); System.out.println(“Roll no=” +rollNo); System.out.println(“Marks=” +marks); }   } class Main { public static void main(String args[]) { Student s1=new Student(); […]

Types of methods in java

Types of methods:   class Methods { public void add()//without returntype/without argument { int a=123; int b=10; System.out.println(“Addition=” +(a+b)); } } class Functiondemo { public static void main(String args[]) { Methods o=new Methods();//classname objectname=new classname(); o.add(); } }   import java.util.*; class Methods { public void sub(int x,int y)//without returntype/with /arguments { System.out.println(“Subtraction=” +(x-y)); } […]

✅ Java Code: Sum of All Nodes (Minimal Version)

Here is a simple and short Java program to find the sum of all nodes in a binary tree using recursion: ✅ Java Code: Sum of All Nodes (Minimal Version) class Node { int data; Node left, right; Node(int data) { this.data = data; } }   public class SumOfNodes {   int sum(Node node) […]

Java Code: Count Leaf Nodes (Minimal Version)

Java Code: Count Leaf Nodes (Minimal Version) Here is a short and simple Java code to count the number of leaf nodes in a binary tree using recursion:   ✅ Java Code: Count Leaf Nodes (Minimal Version class Node { int data; Node left, right; Node(int data) { this.data = data; } }   public […]

EduLearn - Online Education Platform

Welcome to EduLearn!

Start learning today with our wide range of courses taught by industry experts. Gain new skills, advance your career, or explore new interests.

Browse Courses

Popular Courses

[Course Image]

Introduction to Programming

Learn the fundamentals of programming with Python in this beginner-friendly course.

12 Hours Beginner
[Course Image]

Data Science Essentials

Master the basics of data analysis, visualization, and machine learning.

20 Hours Intermediate
[Course Image]

Web Development Bootcamp

Build modern websites with HTML, CSS, JavaScript and popular frameworks.

30 Hours Beginner
[Course Image]

Digital Marketing Fundamentals

Learn SEO, social media marketing, email campaigns and analytics.

15 Hours Beginner
Educational Website Footer