Object Oriented Programming Articles

Page 207 of 589

Printing Integer between Strings in Java

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 1K+ Views

Following is the Java program to print integer between Strings −Examplepublic class Demo{    public static void main(String[] args){       System.out.println("The equals symbol is present between two integer values ");       System.out.println(45+5 + "=" +(56+11));       System.out.println(45+5 + " equals symbol " +(56+11));    } }OutputThe equals symbol is present between two integer values 50=67 50 equals symbol 67A class named Demo contains the main function that prints integer values between two strings.

Read More

Printing Triangle Pattern in Java

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 2K+ Views

Following is the Java program to print Triangle pattern −Exampleimport java.util.*; public class Demo{    public static void main(String[] args){       Scanner my_scan = new Scanner(System.in);       System.out.println("Enter the number of rows which needs to be printed");       int my_row = my_scan.nextInt();       for (int i = 1; i = i; j--){             System.out.print(" ");          }          for (int j = 1; j

Read More

Java Program for Largest K digit number divisible by X

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 241 Views

Following is the Java program for largest K digit number divisible by X −Exampleimport java.io.*; import java.lang.*; public class Demo{    public static int largest_k(int val_1, int val_2){       int i = 10;       int MAX = (int)Math.pow(i, val_2) - 1;       return (MAX - (MAX % val_1));    }    public static void main(String[] args){       int val_1 = 25;       int val_2 = 2;       System.out.println("The largest 2 digit number divisible by 25 is ");       System.out.println((int)largest_k(val_1, val_2));    } }OutputThe largest 2 digit ...

Read More

Java Program for Reversal algorithm for array rotation

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 397 Views

Following is the Java program to implement Reversal algorithm for array rotation −Exampleimport java.io.*; public class Demo{    static void rotate_left(int my_arr[], int no_of_rotation){       int n = my_arr.length;       array_reversal(my_arr, 0, no_of_rotation - 1);       array_reversal(my_arr, no_of_rotation, n - 1);       array_reversal(my_arr, 0, n - 1);    }    static void array_reversal(int my_arr[], int start, int end){       int temp;       while (start < end) {          temp = my_arr[start];          my_arr[start] = my_arr[end];          my_arr[end] = temp; ...

Read More

Max Heap in Java

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 3K+ Views

Max heap is a complete binary tree, wherein the value of a root node at every step is greater than or equal to value at the child node.Below is an implementation of Max Heap using library functions.Exampleimport java.util.*; public class Demo{    public static void main(String args[]){       PriorityQueue my_p_queue = new PriorityQueue(Collections.reverseOrder());       my_p_queue.add(43);       my_p_queue.add(56);       my_p_queue.add(99);       System.out.println("The elements in the priority queue are : ");       Iterator my_iter = my_p_queue.iterator();       while (my_iter.hasNext())       System.out.println(my_iter.next());       my_p_queue.poll();   ...

Read More

Merge two sets in Java

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 3K+ Views

To merge two sets in Java, the code is as follows −Exampleimport java.util.stream.*; import java.util.*; import java.io.*; public class Demo{    public static Set set_merge(Set set_1, Set set_2){       Set my_set = set_1.stream().collect(Collectors.toSet());       my_set.addAll(set_2);       return my_set;    }    public static void main(String[] args){       Set my_set_1 = new HashSet();       my_set_1.addAll(Arrays.asList(new Integer[] { 34, 67, 89, 102 }));       Set my_set_2 = new HashSet();       my_set_2.addAll(Arrays.asList(new Integer[] { 77, 11, 0 , -33}));       System.out.println("The first set contains " + ...

Read More

Run-time Stack mechanism in Java

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 1K+ Views

Eeverytime a process or a code or a thread needs to run in Java, a runtime stack is created so as to store the operations performed while executing the thread.Every entry in the run-time stack is known as stack frame or activation record. Once a function has been called by the process, its associated data is deleted from the runtime stack.Once all the functions have been called, the runtime stack will be empty. This means it needs to be removed from the memory.At this point in time, the runtime stack is destroyed and then the thread is also terminated.A termination ...

Read More

How to write an empty function in Java

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 3K+ Views

Let us see how to write an empty function in Java −Exampleimport java.util.Vector; public class Demo{    public static void my_empty_fun(){    }    public static void main(String[] args){       System.out.println("In the main function");       my_empty_fun();    }   }OutputIn the main functionAn empty function is basically creating a function without defining any operations inside it. A class named Demo contains an empty function named ‘my_empty_fun’ which is just completed by placing two flower brackets, without adding any functionality into it. In the main function, a print statement is written after which the empty function is ...

Read More

Convert one base to other bases in a single Java Program

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 1K+ Views

Let’s say we have an Octal number. To convert Octal to other bases like binary, hexadecimal, etc, the Java code is as follows −Examplepublic class Demo{    public static String base_convert(String num, int source, int destination){       return Integer.toString(Integer.parseInt(num, source), destination);    }    public static void main(String[] args){       String my_num = "345";       int source = 8;       int destination = 2;       System.out.println("Converting the number from octal to binary: "+ base_convert (my_num, source, destination));       destination = 10;       System.out.println("Converting the number from ...

Read More

Java program to generate random numbers within a given range and store in a list

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 459 Views

To generate random numbers in a given range, the Java code is as follows −Exampleimport java.util.Random; import java.util.*; public class Demo{    public static void main(String args[]){       Random my_rand = new Random();       List my_list_1 = new ArrayList();       int v_1 = my_rand.nextInt(1000);       int v_2 = my_rand.nextInt(967);       int v_3 = my_rand.nextInt(1050);       int v_4 = my_rand.nextInt(10000);       int v_5 = my_rand.nextInt(100);       my_list_1.add(v_1);       my_list_1.add(v_2);       my_list_1.add(v_3);       my_list_1.add(v_4);       my_list_1.add(v_5);       System.out.println("The random values in the list are : ");       for(int i=0; i

Read More
Showing 2061–2070 of 5,881 articles
« Prev 1 205 206 207 208 209 589 Next »
Advertisements