Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Articles by Alshifa Hasnain
Page 14 of 23
What is decrement (--) operator in JavaScript?
The decrement operator in Javascript decreases an integer value by one. This operator is often utilized in loops, counters, and mathematical computations where a value has to be decreased sequentially. Types of Decrement Operators The decrement operator (--) can be used in two ways − Post-decrement (x--): It provides the current value of the variable prior to its decrement. Pre-decrement (--x): It first decreases the value and then returns the variable's new value. Syntax x--; // Post-decrement --x; // Pre-decrement Example Below is an example where the value of ...
Read MoreJava Program for Cocktail Sort
In this article, we will learn to perform cocktail sorting in Java. Cocktail Sort, also known as Bidirectional Bubble Sort, is a variation of the standard Bubble Sort algorithm. What is Cocktail Sort? Cocktail Sort works in contrast to bubble sort, wherein elements are iterated from left to right, and the largest element is first brought to its correct position, and so on. In cocktail sort, elements are iterated over in both directions (left and right) in an alternating fashion. Cocktail Sort Working Following are the steps to perform cocktail sort in Java − Traverse ...
Read MoreJavaScript program to count triplets with sum smaller than a given value
In this article, we will learn to count triplets with a sum smaller than a given value in JavaScript. Triplets in an array whose sum is less than a provided number is a popular problem in competitive coding and algorithm design. Problem Statement Given an array of integers and a target sum, we need to find the number of triplets (a, b, c). For exampleInput const arr = [5, 1, 3, 4, 7]; const sum = 12;Output 4 Explanation: The valid triplets are :(1, 3, 5)(1, 3, 4)(1, 4, 5)(1, 3, 7), all having a sum of less than 12. ...
Read MoreJavaScript checking if all the elements are same in an array
In this article, we will learn to check if all the elements are the same in an array in JavaScript. Finding all elements of an array to be the same is a frequent problem in JavaScript, usually needed for data validation, game logic, and algorithm building. Problem Statement We are required to write a JavaScript function that takes in an array of literals. The function should find whether or not all the values in the array are the same. If they are the same, the function should return true, or false otherwise. For Example Input const arr2 = [1, 1, ...
Read MoreJava DatabaseMetaData getURL() method with example
In this article, we will learn about the DatabaseMetaData getURL() method in Java. The DatabaseMetaData interface provides useful methods to obtain details about the database and the JDBC driver. One such method is getURL(), which returns the URL of the JDBC driver being used. What is the getURL() Method? The getURL() method in Java's DatabaseMetaData interface is used to retrieve the URL of the database to which the current connection is established. Syntax String dbUrl = metaData.getURL(); This method retrieves the URL of the underlying Database Management System and returns it in the form of a String variable. ...
Read MoreJavaScript focus a particular element with div class, not div id declaration?
In this article, we will learn to focus on a particular element with a div class in JavaScript. In JavaScript setting focus on an element is commonly done using the focus() method. What is the focus() method? The focus() method in JavaScript is used to bring a specific element into focus. This means the element becomes active, allowing the user to interact with it, such as typing in an input field or highlighting a section of the webpage. Syntax element.focus(); Here, the element is the DOM element that will receive the focus. Using JavaScript to Focus on a Class Element ...
Read MoreJava program to subtract 40 days from the calendar
In this article, we will learn to subtract 40 days from the calendar in Java. Working with dates is a frequent need in programming, and there are multiple methods of doing it in Java. One of the simplest approaches is to use the Calendar class to remove days from a date. Different Approaches The following are the two to subtract 40 days from the calendar in Java − Using the Calendar Class Using the LocalDate Class Using the Calendar Class The first approach utilizes the Calendar class, which is part ...
Read MoreJavaScript program to generate all rotations of a number
In this article, we will learn to generate all rotations of a number in JavaScript. Producing a primary common problem such as all its rotations comprises the creation of all possible permutations of the digits by rotating its digits. Problem Statement The goal is that if we have given a number, we need to generate all possible rotations of its digits. A rotation is defined as moving the first digit to the end of the number. For exampleInput 123 Explanation 123 (original number) 231 (first rotation: move 1 to the ...
Read MoreJava program to map string list to lowercase and sort
In this article, we will learn to map a String list to lowercase and sort in Java. We need to manipulate the elements of a list, such as converting all strings to lowercase and sorting them. This is particularly useful when dealing with user input, file processing, or data normalization. Problem Statement Given a list of strings, we want to convert all strings to lowercase and sort the list in reverse alphabetical order.For Example: Input ["Apple", "banana", "Cherry", "date"] Output ["date", "cherry", "banana", "apple"] Using Streams API The Streams API provides a useful and functional approach to processing ...
Read MoreJava program to display date and time information in uppercase
In this article, we will learn to display the date and time in uppercase using Java. Working with date and time in Java is a common requirement in various applications, logging, scheduling, or data processing. Different Approaches The following are the two different approaches to display the date and time in uppercase using Java − Using Formatter and Calendar Using DateTimeFormatter Using Formatter and Calendar The Formatter class in Java allows us to format date and time using the %Tc specifier. We can then convert the output to uppercase using ...
Read More