Object Oriented Programming Articles

Page 206 of 589

Refresh page after clearing all form fields in jQuery?

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

To refresh page, use the location.reload() in JavaScript. The sample JavaScript code is as follows −Example Document UserName: Password: Refresh Page    $('#RefreshPage').click(function() {       location.reload();    }); To run the above program, save the file name “anyName.html(index.html)” and right click on the file. Select the option “Open with Live Server” in VS Code editor.OutputThis will produce the following output −After filling the form, the snapshot is as follows −When you click the button “Refresh Page”, the page will refresh and the following output is visible −

Read More

Place an H1 element and its text at a particular index in jQuery

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 594 Views

To set an element and it’s text, use the text() method in jQuery. With that, use the :nth-child selector to place it at a particular position. Following is the code −Example Document JavaScript MySQL MongoDB Java C#    $('h1:nth-child(4)').text("Python"); To run the above program, save the file name “anyName.html(index.html)” and right click on the file. Select the option “Open with Live Server” in VS Code editor.OutputThis will produce the following output −

Read More

How to clear screen using Java?

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

Following is the code to clear screen using Java −Examplepublic class Demo{    public static void main(String[] args){       System.out.print("\033[H\033[2J");       System.out.flush();    } }OutputThe screen would be clearedA class named Demo contains the main function. Here, the ANSI escape code is written, that clears the screen. The flush function resets the cursor to the top of the window screen.

Read More

Java Program for Counting Sort

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 281 Views

The Counting Sort counts the number of objects having distinct key values. Let us see an example −Note − The below code can be used with negative numbers as well.Exampleimport java.util.*; public class Demo{    static void count_sort(int[] arr){       int max_val = Arrays.stream(arr).max().getAsInt();       int min_val = Arrays.stream(arr).min().getAsInt();       int range = max_val - min_val + 1;       int count[] = new int[range];       int result[] = new int[arr.length];       for (int i = 0; i < arr.length; i++){          count[arr[i] - min_val]++;   ...

Read More

Java Program for Comb Sort

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 334 Views

The Comb Sort in Java eliminates the smaller values situated to the end of the list and the inversions are removed oby by one. Let us see an example −Exampleimport java.util.Arrays; public class Demo{    void comb_sort(int nums[]){       int len_gap = nums.length;       float shrink_val = 1.3f;       boolean swap = false;       while (len_gap > 1 || swap) {          if (len_gap > 1) {             len_gap = (int)(len_gap / shrink_val);          }          swap = ...

Read More

Java Program for Anagram Substring Search

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 290 Views

Following is an example for Anagram Substring Search in Java −Examplepublic class Demo{    static final int max_val = 256;    static boolean compare_vals(char my_arr_1[], char my_arr_2[]){       for (int i = 0; i < max_val; i++)       if (my_arr_1[i] != my_arr_2[i])       return false;       return true;    }    static void search_subs(String my_pattern, String my_text){       int pat_len = my_pattern.length();       int txt_len = my_text.length();       char[] count_pat = new char[max_val];       char[] count_txt = new char[max_val];       for (int ...

Read More

String Formatting in Java using %

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 226 Views

Followimg is the code to implement String formatting in Java using % −Examplepublic class Demo {    public static void main(String args[]){       String my_str = " sample.";       String concat_Str = String.format("This is a" + "%s", my_str);       String format_str_1 = String.format("The value is %.4f", 78.92367);       System.out.println(concat_Str);       System.out.println(format_str_1);    } }OutputThis is a sample. The value is 78.9237A class named Demo contains the main function. Here a string value is defined, which is used to format the string, by concatenating it to another variable. Similarly, a floating ...

Read More

Java Program to find largest prime factor of a number

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

Following is the Java code to find the largest prime factor of a number −Exampleimport java.io.*; import java.util.*; public class Demo{    static long maxPrimeFactors( long val){       long max_prime = -1;       while (val % 2 == 0) {          max_prime = 2;          val >>= 1;       }       for (int i = 3; i 2)       max_prime = val;       return max_prime;    }    public static void main(String[] args){       int val = 148592;   ...

Read More

Java Program to find the perimeter of a cylinder

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 323 Views

Following is the Java code to find the perimeter of a cylinder −Exampleimport java.io.*; public class Demo{    static int find_peri(int dia, int ht){       return 2*(dia + ht);    }    public static void main(String[] args){       int dia = 7;       int ht = 15;       System.out.println("The perimeter of the cylinder is " + find_peri(dia, ht) + " units");    } }OutputThe perimeter of the cylinder is 44 unitsA class named Demo defines a static function that takes in two values, diameter and height. This function computes the sum of ...

Read More

Java Program to find the vertex, focus and directrix of a parabola

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 245 Views

Following is the Java program to find the vertex, focus and directrix of a parabola −Examplepublic class Demo{    public static void find_values(float val_1, float val_2, float val_3){       System.out.println("The value of vertex is (" + (-val_2 / (2 * val_1)) + ", "+ (((4 * val_1 * val_3) - (val_2 * val_2)) / (4 * val_1)) + ")");       System.out.println("The value of focus is (" + (-val_2 / (2 * val_1)) + ", " + (((4 * val_1 * val_3) - (val_2 * val_2) + 1) / (4 * val_1)) + ")");       ...

Read More
Showing 2051–2060 of 5,881 articles
« Prev 1 204 205 206 207 208 589 Next »
Advertisements