Get HREF Value in JavaScript

Yaswanth Varma
Updated on 21-Jun-2024 14:31:30

13K+ Views

JavaScript Get href Value is a useful tool for web developers and designers who need to quickly access the value of an HTML element's href attribute. This article will provide step-by-step instructions on how to use JavaScript to get the value of an href attribute on a webpage, as well as some tips and tricks for getting the most out of this powerful feature. The ability to quickly obtain the values from an HTML element's attributes can help make development faster and more efficient, so let's get started! The value of the href attribute in JavaScript is a URL ... Read More

Add Two Numbers in Java

AmitDiwan
Updated on 21-Jun-2024 14:21:29

11K+ Views

When we enter the coding world there are various mathematical operations that we learn to do through programming languages. We are expected to begin our coding journey with basic mathematical operations like adding, subtracting, multiplying and dividing. To evaluate the sum of two numbers, we use the '+' operator. However, Java also provides other approaches for adding two numbers. This article aims to explore the possible ways to add the two numbers in Java. To add the two numbers in Java, we are going to use the following approaches − By taking input of operands from user By ... Read More

Convert Integer to Binary in Java

karthikeya Boyini
Updated on 21-Jun-2024 13:59:18

13K+ Views

To convert an integer to binary, use the Integer.toBinaryString() method in Java.Let’s say the following is the integer we want to convert.int val = 999;Converting the above integer to binary.Integer.toBinaryString(val)Example Live Demopublic class Demo {     public static void main(String[] args) {        int val = 999;        // integer        System.out.println("Integer: "+val);        // binary        System.out.println("Binary = " + Integer.toBinaryString(val));     } }OutputInteger: 999 Binary = 1111100111

Convert String to Boolean in Java

Samual Sam
Updated on 21-Jun-2024 13:09:42

16K+ Views

To convert String to Boolean, use the parseBoolean() method in Java. The parseBoolean() parses the string argument as a boolean. The boolean returned represents the value true if the string argument is not null and is equal, ignoring case, to the string "true".Firstly, declare a string.String str = "false";Now, use the Boolean.parseBoolean() method to convert the above declared String to Boolean.boolean bool = Boolean.parseBoolean(str);Let us now see the complete example to learn how to convert String to Boolean.Example: Convert String to Boolean Live Demopublic class Demo {    public static void main(String[] args) {       // string     ... Read More

Calculate Product of Two Numbers in Java

Samual Sam
Updated on 21-Jun-2024 12:47:09

12K+ Views

The * operator in Java is used to multiply two numbers. Read required numbers from the user using Scanner class and multiply these two integers using the * operator.Exampleimport java.util.Scanner; public class MultiplicationOfTwoNumbers {    public static void main(String args[]){       Scanner sc = new Scanner(System.in);       System.out.println("Enter the value of the first number ::");       int a = sc.nextInt();       System.out.println("Enter the value of the first number ::");       int b = sc.nextInt();       int result = a*b;       System.out.println("Product of the given two numbers ... Read More

Count Character Occurrences in a String Using HashMap in Java

AmitDiwan
Updated on 21-Jun-2024 12:41:28

13K+ Views

To count the occurrence of each character in a string using Hashmap, the Java code is as follows −Example Live Demoimport java.io.*; import java.util.*; public class Demo{    static void count_characters(String input_str){       HashMap my_map = new HashMap();       char[] str_array = input_str.toCharArray();       for (char c : str_array){          if (my_map.containsKey(c)){             my_map.put(c, my_map.get(c) + 1);          }else{             my_map.put(c, 1);          }       }       for (Map.Entry entry : my_map.entrySet()){ ... Read More

Locate a Character in a String in Java

Samual Sam
Updated on 21-Jun-2024 11:27:10

15K+ Views

To locate a character in a string, use the indexOf() method.Let’s say the following is our string.String str = "testdemo";Find a character ‘d’ in a string and get the index.int index = str.indexOf( 'd');Example Live Demopublic class Demo {    public static void main(String []args) {       String str = "testdemo";       System.out.println("String: "+str);       int index = str.indexOf( 'd' );       System.out.printf("'d' is at index %d, index);    } }OutputString: testdemo 'd' is at index 4Let us see another example. The method returns -1, if the character isn’t found −Example Live Demopublic class ... Read More

Find the 2nd Smallest Number in an Array in Java

Ankith Reddy
Updated on 21-Jun-2024 11:21:08

12K+ Views

To find the 2nd smallest element of the given array, first of all, sort the array.Sorting an arrayCompare the first two elements of the arrayIf the first element is greater than the second swap them.Then, compare 2nd and 3rd elements if the second element is greater than the 3rd swap them.Repeat this till the end of the array.After sorting an array print the 2nd element of the array.ExampleLive Demopublic class SmallestNumberInAnArray {    public static void main(String args[]){       int temp, size;       int array[] = {10, 20, 25, 63, 96, 57};       size = array.length;       for(int i = 0; i

Convert a Set to an Array in Java

Lakshmi Srinivas
Updated on 21-Jun-2024 11:15:54

15K+ Views

The Set object provides a method known as toArray(). This method accepts an empty array as argument, converts the current Set to an array and places in the given array. To convert a Set object to an array − Create a Set object. Add elements to it. Create an empty array with size of the created Set. Convert the Set to an array using the toArray() method, bypassing the above-created array as an argument to it. Print the contents of the array.ExampleLive Demoimport java.util.HashSet; import java.util.Set; public class SetToArray {    public static void main(String args[]){       Set set = new HashSet();   ... Read More

Binding of a Variable in C Language

Bhanu Priya
Updated on 20-Jun-2024 21:52:52

2K+ Views

Storage classes specify the scope, lifetime and binding of variables.To fully define a variable, one needs to mention not only its ‘type’ but also its storage class.A variable name identifies some physical location within computer memory, where a collection of bits are allocated for storing values of variable.Storage class tells us the following factors −Where the variable is stored (in memory or cpu register)?What will be the initial value of variable, if nothing is initialized?What is the scope of variable (where it can be accessed)?What is the life of a variable?BindingBinding finds the corresponding binding occurrence (declaration/definition) for an applied ... Read More

Advertisements