code-rag-bench/online-tutorials huggingface dataset:
What is constructor chaining in Java?

Constructors are similar to methods but,
They do not have any return type.
The name of the constructor is same as the name of the class.
Every class has a constructor. If we do not explicitly write a constructor for a class, the Java compiler builds a default constructor for that class.
Each time a new object is created, at least one constructor will be invoked.
A class can have more than one constructor.
this() and super() are used to call constructors explicitly. Where, using this() you can call the current class’s constructor and using super() you can call the constructor of the super class.
You can also call one constructor from another.
Calling a constructor of one class from other is known as constructor chaining. From normal (default) constructor you can call the parameterized constructors of the same class using this() and, from the sub class you can call the constructor of the super class using super()
 Live Demo
class Super{
   Super(int data){
      System.out.println("value is : "+ data);
   }
}
public class Sub extends Super{
   Sub(int data) {
      super(data);
   }
   public static void main(String args[]){
      Sub sub = new Sub(400);
   }
}

value is : 400
C++ Program for Range sum queries without updates - GeeksforGeeks

06 Dec, 2018
Given an array arr of integers of size n. We need to compute sum of elements from index i to index j. The queries consisting of i and j index values will be executed multiple times.
Examples:
Input : arr[] = {1, 2, 3, 4, 5}
        i = 1, j = 3
        i = 2, j = 4
Output :  9
         12         

Input : arr[] = {1, 2, 3, 4, 5}
        i = 0, j = 4 
        i = 1, j = 2 
Output : 15
          5

// CPP program to find sum between two indexes// when there is no update.#include <bits/stdc++.h>using namespace std;  void preCompute(int arr[], int n, int pre[]){    pre[0] = arr[0];    for (int i = 1; i < n; i++)        pre[i] = arr[i] + pre[i - 1];}  // Returns sum of elements in arr[i..j]// It is assumed that i <= jint rangeSum(int i, int j, int pre[]){    if (i == 0)        return pre[j];      return pre[j] - pre[i - 1];}  // Driver codeint main(){    int arr[] = { 1, 2, 3, 4, 5 };    int n = sizeof(arr) / sizeof(arr[0]);      int pre[n];    preCompute(arr, n, pre);    cout << rangeSum(1, 3, pre) << endl;    cout << rangeSum(2, 4, pre) << endl;      return 0;}
9
12

Please refer complete article on Range sum queries without updates for more details!
C++ Programs
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Passing a function as a parameter in C++
Program to implement Singly Linked List in C++ using class
cout in C++
Pi(π) in C++ with Examples
Const keyword in C++
Handling the Divide by Zero Exception in C++
Why it is important to write "using namespace std" in C++ program?
isdigit() function in C/C++ with Examples
Dynamic _Cast in C++
Setting up Sublime Text for C++ Competitive Programming Environment
Perl last Statement

When  a last statement is encountered inside a loop, the loop is immediately terminated and the program control resumes at the next statement following the loop.  You can provide a LABEL with last statement where LABEL is the label for a loop. A last statement can be used inside a nested loop where it will be applicable to the nearest loop if a LABEL is not specified.
If there is any continue block on the loop, then it is not executed. You will see the continue statement in a separate chapter.
The syntax of a last statement in Perl is −
last [LABEL];

#!/usr/local/bin/perl

$a = 10;
while( $a < 20 ) {
   if( $a == 15) {
      # terminate the loop.
      $a = $a + 1;
      last;
   }
   print "value of a: $a\n";
   $a = $a + 1;
}
When the above code is executed, it produces the following result −
value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14

Let's take one example where we are going to use a LABEL along with next statement −
#!/usr/local/bin/perl

$a = 0;
OUTER: while( $a < 4 ) {
   $b = 0;
   print "value of a: $a\n";
   INNER:while ( $b < 4) {
      if( $a == 2) {
         # terminate outer loop
         last OUTER;
      }
      $b = $b + 1;
      print "Value of b : $b\n";
   }
   print "\n";
   $a = $a + 1;
}
When the above code is executed, it produces the following result −
value of a : 0
Value of b : 1
Value of b : 2
Value of b : 3
Value of b : 4

value of a : 1
Value of b : 1
Value of b : 2
Value of b : 3
Value of b : 4

value of a : 2


    46 Lectures 
     4.5 hours 

 Devi Killada

    11 Lectures 
     1.5 hours 

 Harshit Srivastava

    30 Lectures 
     6 hours 

 TELCOMA Global

    24 Lectures 
     2 hours 

 Mohammad Nauman

    68 Lectures 
     7 hours 

 Stone River ELearning

    58 Lectures 
     6.5 hours 

 Stone River ELearning
 Print
 Add Notes
 Bookmark this page
ES6 | Environment Setup - GeeksforGeeks

05 Aug, 2021
ES6 can run on local machines, only it needs a browser and a text editor. Otherwise, ES6 can run on any host, on any OS. For ES6, it may not be an all-time execute on the browsers. So we need some extra mechanism to executes the ES6 version.  
NodeJS
Code Editor
Browser
NodeJS: For web server, NodeJS is an open-source, cross-platform, JavaScript run-time environment that executes JavaScript code outside of a browser. To install the NodeJS in your machine follow the below links.  
Installation of Node.js on Windows
Installation of Node.js on Linux
Code Editor: To write the executable code we will require a text editor. In my opinion, VS code editor is the first choice you can choose. To install VS Code follow the below links. 
First, you have to download and install the Visual Studio. For that, you can refer to Downloading and Installing Visual Studio.
Browser: To run the ES6 program. I prefer to use Google Chrome, there are so many other browsers like Firefox, Internet Explorer, Safari.Execute the ES6 code:  
Step 1: Now make a folder anywhere of your PC and run command prompt in that folder and make a HTML file by using VS Code editor paste the below code inside the file and save it.  
html
<!DOCTYPE HTML><html lang="en">    <head>        <meta charset="UTF-8"/>        <meta name="viewport"              content="width=device-width,              initial-scale=1.0"/>        <meta http-equiv= "X-UA-Compatible"              content="ie=edge"/>        <title>hello world!</title>    </head>    <body>        <h1>GeeksforGeeks</h1>        <b>A Computer Science Portal for Geeks</b>    </body></html>
Step 2: Then write the below command in the command prompt, and hit enter.  
npm install http-server -g
npm is a package manager for the JavaScript programming, by default it is provided by the NodeJS. Full form of npm is Node Package manager. It has many libraries and we can easily use them by Node. here we are use a library http-server to establish server.  
Step 3: Then, after the installation below command will turn on the server.  
http-server -p 1234
//1234 is a random port number
 
Step 4: After that, open your browser and write below URL in the search box. Then, the HTML page you make earlier after making the folder will show on the web.  
localhost:1234/filename.html
 
 
surinderdawra388
ES6
JavaScript-Misc
Picked
JavaScript
Node.js
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Difference between var, let and const keywords in JavaScript
Difference Between PUT and PATCH Request
Remove elements from a JavaScript Array
How to get character array from string in JavaScript?
How to filter object array based on attributes?
Installation of Node.js on Linux
Node.js fs.readFileSync() Method
How to update Node.js and NPM to next version ?
Node.js fs.readFile() Method
Node.js fs.writeFile() Method
Differentiate between Ambiguous and Unambiguous Grammar

Before understanding the differences between ambiguous grammar and unambiguous grammar, let us learn about these concepts.
A grammar is said to be ambiguous if there exists more than one left most derivation or more than one right most derivation or more than one parse tree for a given input string.
If the grammar is not ambiguous then we call unambiguous grammar
If the grammar is not ambiguous then we call unambiguous grammar
If the grammar has ambiguity then it is good for compiler construction
If the grammar has ambiguity then it is good for compiler construction
No method can automatically detect and remove the ambiguity, but we can remove the ambiguity by re-writing the whole grammar without ambiguity.
No method can automatically detect and remove the ambiguity, but we can remove the ambiguity by re-writing the whole grammar without ambiguity.
Let us consider a grammar with production rules −
E=I
E=E+E
E=E*E
E=(E)
E= ε|0|1|2|3......9
A grammar can be unambiguous if the grammar does not contain ambiguity that means if it does not contain more than one left most derivation or more than one right most derivation or more than one parse tree for the given input string.
S -> AB
A -> Aa / a
B -> b
The major differences between ambiguous and unambiguous grammar are as follows −
degrees() and radians() in Python

The measurements of angles in mathematics are done using these two units of measurement called degree and radian. They are frequently used in math calculations involving angles and need conversion from one value to another. In python we can achieve these conversions using python functions.
This function takes radian value as parameter and return the equivalent value in degrees. The return is a float value.
 Live Demo
import math
# Printing degree equivalent of radians.
print("1 Radians in Degrees : ",math.degrees(1))
print("20 Radians in Degrees : ",math.degrees(20))
print("180 Radians in Degrees : ",math.degrees(180))
Running the above code gives us the following result −
1 Radians in Degrees : 57.29577951308232
20 Radians in Degrees : 1145.9155902616465
180 Radians in Degrees : 10313.240312354817
This function takes degree value as parameter and return the equivalent value in radians. The return is a float value.
 Live Demo
import math
# Printing radian equivalent of degrees.
print("1 degrees in radian : ",math.radians(1))
print("60 degrees in radian : ",math.radians(60))
print("180 degrees in radian : ",math.radians(180))
Running the above code gives us the following result −
1 degrees in radian : 0.017453292519943295
60 degrees in radian : 1.0471975511965976
180 degrees in radian : 3.141592653589793
numpy package also has inbuilt functions which can directlyconver degrees to radian and vice versa. These functions are names deg2rad and rad2deg.
 Live Demo
import numpy as np
# Printing radian equivalent of degrees.
print("1 degrees to radian : ",np.deg2rad(1))
print("1 radian to degree : ",np.rad2deg(1))
Running the above code gives us the following result^−
1 degrees to radian : 0.017453292519943295
1 radian to degree : 57.29577951308232
set count() function in C++ STL - GeeksforGeeks

08 Jun, 2021
The set::count() is a built-in function in C++ STL which returns the number of times an element occurs in the set. It can only return 1 or 0 as the set container contains unique elements only. Syntax:  
set_name.count(element) 
Parameters: The function accepts one mandatory parameter element which specifies the element whose count is to be returned. Return Value: The function returns 1 or 0 as the set contains unique elements only. It returns 1 if the value is present in the set container. It returns 0 if it is not present in the container. 
Time Complexity : Time Complexity for count function is O(log N) where N is the number of elements present in the set
Difference between count and find function in a set is count returns 0 or 1 depending upon whether element is not present or present respectively whereas find function returns a iterator pointing to the value if present else next to the last value in the set.Below is the illustration of the above function. 
CPP
// CPP program to demonstrate the// set::count() function#include <bits/stdc++.h>using namespace std;int main(){     int arr[] = { 14, 12, 15, 11, 10 };     // initializes the set from an array    set<int> s(arr, arr + 5);     // check if 11 is present or not    if (s.count(11))        cout << "11 is present in the set\n";    else        cout << "11 is not present in the set\n";     // checks if 18 is present or not    if (s.count(18))        cout << "18 is present in the set\n";    else        cout << "18 is not present in the set\n";     return 0;}
11 is present in the set
18 is not present in the set
 
noah28
CPP-Functions
cpp-set
STL
C++
STL
CPP
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Operator Overloading in C++
Constructors in C++
Socket Programming in C/C++
Virtual Function in C++
Multidimensional Arrays in C / C++
Templates in C++ with Examples
Copy Constructor in C++
rand() and srand() in C/C++
Polymorphism in C++
C++ Data Types
Program to Count number of binary strings without consecutive 1’s in C/C++?

Here we will see one interesting problem. Suppose one value of n is given. We have to find all strings of length n, such that there are no consecutive 1s. If n = 2, then the numbers are {00, 01, 10}, So output is 3.
We can solve it using dynamic programming. Suppose we have a tables ‘a’ and ‘b’. Where arr[i] is storing the number of binary strings of length i, where no consecutive 1s are present, and ending with 0. Similarly, b is holding the same but numbers ending with 1. We can append 0 or 1 where last one is 0, but add only 0 if the last one is 1.
Let us see the algorithm to get this idea.
noConsecutiveOnes(n) −
Begin
   define array a and b of size n
   a[0] := 1
   b[0] := 1
   for i in range 1 to n, do
      a[i] := a[i-1] + b[i - 1]
      b[i] := a[i - 1]
   done
   return a[n-1] + b[n-1]
End
#include <iostream>
using namespace std;
int noConsecutiveOnes(int n) {
   int a[n], b[n];
   a[0] = 1;
   b[0] = 1;
   for (int i = 1; i < n; i++) {
      a[i] = a[i-1] + b[i-1];
      b[i] = a[i-1];
   }
   return a[n-1] + b[n-1];
}
int main() {
   cout << noConsecutiveOnes(4) << endl;
}
8
VBA - Concatenation Operators

Following Concatenation operators are supported by VBA.
Assume variable A holds 5 and variable B holds 10 then −
Try the following example to understand the Concatenation operator available in VBScript −
Private Sub Constant_demo_Click()
   Dim a as Integer : a = 5
   Dim b as Integer : b = 10
   Dim c as Integer

   c = a + b  
   msgbox ("Concatenated value:1 is " &c) 'Numeric addition 
   
   c = a & b 
   msgbox ("Concatenated value:2 is " &c) 'Concatenate two numbers 
End Sub
Try the following example to understand all the Logical operators available in VBA by creating a button and adding the following function.
Concatenated value:1 is 15

Concatenated value:2 is 510

Concatenation can also be used for concatenating two strings. Assume variable A = "Microsoft" and variable B = "VBScript" then −
Try the following example to understand all the Logical operators available in VBA by creating a button and adding the following function.
Private Sub Constant_demo_Click()
   Dim a as String : a = "Microsoft"
   Dim b as String : b = "VBScript"
   Dim c as String

   c = a + b 
   msgbox("Concatenated value:1 is " &c) 'addition of two Strings
   
   c = a & b 
   msgbox("Concatenated value:2 is " &c) 'Concatenate two String
End Sub
When you save it as .html and execute it in the Internet Explorer, then the above script will produce the following result.
Concatenated value:1 is MicrosoftVBScript

Concatenated value:2 is MicrosoftVBScript


    101 Lectures 
     6 hours 

 Pavan Lalwani

    41 Lectures 
     3 hours 

 Arnold Higuit

    80 Lectures 
     5.5 hours 

 Prashant Panchal

    25 Lectures 
     2 hours 

 Prashant Panchal

    26 Lectures 
     2 hours 

 Arnold Higuit

    92 Lectures 
     10.5 hours 

 Vijay Kumar Parvatha Reddy
 Print
 Add Notes
 Bookmark this page
What is the difference between a python module and a python package?

Any Python file is a module, its name being the file's base name/module's __name__ property without the .py extension. A package is a collection of Python modules, i.e., a package is a directory of Python modules containing an additional __init__.py file. The __init__.py distinguishes a package from a directory that just happens to contain a bunch of Python scripts. Packages can be nested to any depth, provided that the corresponding directories contain their own __init__.py file.
When you import a module or a package, the corresponding object created by Python is always of type module. This means that the distinction between module and package is just at the file system level. Note, however, when you import a package, only variables/functions/classes in the __init__.py file of that package are directly visible, not sub-packages or modules.
For example, in the datetime module, there is a submodule called date. When you import datetime, it won't be imported. You'll need to import it separately.
>>> import datetime
>>> date.today()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'date' is not defined
>>> from datetime import date
>>> date.today()
datetime.date(2017, 9, 1)
Java Examples - Exception with overloaded Methods

How to handle the exception with overloaded methods ?
This example shows how to handle the exception with overloaded methods. You need to have a try catch block in each method or where the are used.
public class Main {
   double method(int i) throws Exception {
      return i/0;
   }
   boolean method(boolean b) {
      return !b;
   }
   static double method(int x, double y) throws Exception {
      return x + y ;
   }
   static double method(double x, double y) {
      return x + y - 3;
   }   
   public static void main(String[] args) {
      Main mn = new Main();
      try {
         System.out.println(method(10, 20.0));
         System.out.println(method(10.0, 20));
         System.out.println(method(10.0, 20.0));
         System.out.println(mn.method(10));
      } catch (Exception ex) {
         System.out.println("exception occoure: "+ ex);
      }
   }
}
The above code sample will produce the following result.
30.0
27.0
27.0
exception occoure: java.lang.ArithmeticException: / by zero

The following is an another example to handle the exception with overloaded methods in Java
class NewClass1 { 
   void msg()throws Exception{System.out.println("this is parent");}
}
public class NewClass extends NewClass1 {
   NewClass() {
   }
   void msg()throws ArithmeticException{System.out.println("This is child");}
   public static void main(String args[]) {
      NewClass1 n = new NewClass();
      try {
         n.msg();
      } catch(Exception e){}
   }  
}
The above code sample will produce the following result.
This is child

 Print
 Add Notes
 Bookmark this page
Passing and Returning Objects in Java

As we know it is core concept that in Java there is always pass by value and not by pass by reference.So in this post we will focus on that how this concept get validated in case of passing primitive and passing reference to a method.
In case when a primitive type is passed to a method as argument then the value assigned to this primitive is get passed to the method and that value becomes local to that method,which means that any change to that value by the method would not change the value of primitive that you have passed to the method.
While in case of passing reference to a method again Java follow the same rule of pass by value now let understand how it happens.
As we know that a reference in Java holds the memory location of object created if it is assigned to that reference otherwise it is initiated as null.Now the point to remember here is that the value of the reference is the memory location of the assigned object,so whenever we pass the reference to any method as argument then we actually pass the memory location of that object which is assigned to that particular reference.This technically means that the target method has memory location of our created object and can access it to.So in case if target method access our object and make changes to any of property of it than we would encounter with the changed value in our original object.
 Live Demo
public class PassByValue {
   static int k =10;
   static void passPrimitive(int j) {
      System.out.println("the value of passed primitive is " + j);
      j = j + 1;
   }
   static void passReference(EmployeeTest emp) {
      EmployeeTest reference = emp;
      System.out.println("the value of name property of our object is "+ emp.getName());
      reference.setName("Bond");
   }
   public static void main(String[] args) {
      EmployeeTest ref = new EmployeeTest();
      ref.setName("James");
      passPrimitive(k);
      System.out.println("Value of primitive after get passed to method is "+ k);
      passReference(ref);
      System.out.println("Value of property of object after reference get passed to method is "+          ref.getName());
   }
}
class EmployeeTest {
   String name;
   public String getName() {
      return name;
   }
   public void setName(String name) {
      this.name = name;
   }
}
the value of passed primitive is 10
Value of primitive after get passed to method is 10
the value of name property of our object is James
Value of property of object after reference get passed to method is Bond
SQL | UNION Operator

28 Aug, 2020
The UNION operator could be used to find the result-set or combination of two or more tables.
Terms and Condition for using UNION :
Each table used within UNION must have the same number of columns.
The columns must have same data types.
The columns in each table must be in the same order.
1. UNION Syntax :
SELECT columnnames FROM table1
UNION
SELECT columnnames FROM table2;

UNION operator provides only unique values by default. To find duplicate values, use UNION ALL :
2. UNION ALL Syntax :
SELECT columnnames FROM table1
UNION ALL
SELECT columnnames FROM table2;

Let’s assume we have two tables “Geeks1” and “Geeks2”;
Select * 
from Geeks1; 
Select * 
from Geeks2; 
SQL UNION Example –The below SQL statement finds the cities (only unique values) from both the “Geeks1” and the “Geeks2” table :
Example –
SELECT City 
FROM Geeks1

UNION

SELECT City 
FROM Geeks2
ORDER BY City; 
Output –
SQL UNION ALL Example –The below SQL statement finds the cities (duplicate values also) from both the “Geeks1” and the “Geeks2” table :
Example –
SELECT City 
FROM Customers

UNION ALL

SELECT City 
FROM Suppliers
ORDER BY City; 
Output –
DBMS-SQL
DBMS
SQL
DBMS
SQL
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Types of Functional dependencies in DBMS
Difference between OLAP and OLTP in DBMS
MySQL | Regular expressions (Regexp)
What is Temporary Table in SQL?
SQL | DDL, DML, TCL and DCL
SQL | DDL, DQL, DML, DCL and TCL Commands
How to find Nth highest salary from a table
SQL | ALTER (RENAME)
How to Update Multiple Columns in Single Update Statement in SQL?
SQL | Sub queries in From Clause
Stack.Contains() Method in C#

04 Feb, 2019
This method(comes under System.Collections namespace) is used to check whether a specified element is present is Stack or not. Internally this method checks for equality by calling the Object.Equals method. Also, it performs a linear search, therefore, this method is an O(n) operation, where n is Count.
Syntax:
public virtual bool Contains (object obj);
Here, obj is the object to locate in the Stack. The value can be null.
Return Value: It returns true, if obj is found in the Stack otherwise returns false.
Below programs illustrate the use of above-discussed method:
Example 1:
// C# code to illustrate the// Stack.Contains() Methodusing System;using System.Collections;  class GFG {      // Driver code    public static void Main()    {          // Creating a Stack        Stack myStack = new Stack();          // Inserting the elements into the Stack        myStack.Push("Geeks");        myStack.Push("Geeks Classes");        myStack.Push("Noida");        myStack.Push("Data Structures");        myStack.Push("GeeksforGeeks");          // Checking whether the element is        // present in the Stack or not        // The function returns True if the        // element is present in the Stack,         // else returns False        Console.WriteLine(myStack.Contains("GeeksforGeeks"));    }}
True

Example 2:
// C# code to illustrate the// Stack.Contains() Methodusing System;using System.Collections;  class GFG {      // Driver code    public static void Main()    {          // Creating a Stack        Stack myStack = new Stack();          // Inserting the elements         // into the Stack        myStack.Push(5);        myStack.Push(10);        myStack.Push(15);        myStack.Push(20);        myStack.Push(25);          // Checking whether the element is        // present in the Stack or not        // The function returns True if the        // element is present in the Stack, else        // returns False        Console.WriteLine(myStack.Contains(7));    }}
False

Reference:
https://docs.microsoft.com/en-us/dotnet/api/system.collections.stack.contains?view=netframework-4.7.2
CSharp-Collections-Namespace
CSharp-Collections-Stack
CSharp-method
C#
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
HTML <ul> Tag

09 Dec, 2021
In this article, we will know the HTML <ul> Tag & its implementation. The <ul> tag in HTML is used to define the unordered list item in an HTML document. It contains the list items <li> element. The <ul> tag requires an opening and closing tag. By using CSS style you can easily design an unordered list.
Syntax: 
<ul> list of items </ul>
Accepted attribute: This tag contains two attributes which are listed below: 
HTML <ul> compact Attribute: It will render the list smaller.
HTML <ul> type Attribute: It specifies which kind of marker is used in the list.
Note: The <ul> attributes are not supported by HTML 5.
Example: In this example, we have created an unordered list of computer parts using the <ul> tag.
HTML
<!DOCTYPE html><html>  <body>  <h2>Welcome To GeekforGeeks</h2>  <ul>    <li>Mouse</li>    <li>Keyboard</li>    <li>Speaker</li>    <li>Monitor</li>  </ul></body>  </html>
Output:
HTML Unordered List
Example 1: This example describes the Unordered List in HTML.
HTML
<!DOCTYPE html><html>  <head>  <title>HTML ul tag</title></head>  <body>  <h1>GeeksforGeeks</h1>  <h2>HTML ul tag</h2>  <p>GeeksforGeeks courses List:</p>  <ul>    <li>Geeks</li>    <li>Sudo</li>    <li>Gfg</li>    <li>Gate</li>    <li>Placement</li>  </ul></body>  </html>
Output:
HTML Unordered List
Example 2: Nested unordered list, a list inside other lists is known as a nested list.
HTML
<!DOCTYPE html><html>  <head>  <title>Nested unordered list</title></head>  <body>  <h2>Welcome To GeeksforGeeks</h2>  <ul>    <li>Hardware</li>    <li>      Software      <ul>        <li>System Software</li>        <li>Application Software</li>      </ul>    </li>    <li>MacBook</li>  </ul></body>  </html>
Output:
Nested Unordered List
Example 3: Complex nested unordered list.
HTML
<!DOCTYPE html><html>  <head>  <title>Nested unordered list</title></head>  <body>  <h2>Welcome To GeeksforGeeks</h2>  <ul>    <li>Hardware</li>    <li>      Software      <ul>        <li>System Software</li>        <li>Application Software</li>        <ul>          <li>Skype</li>          <li>Slack</li>        </ul>        <li>Microsoft suite of products</li>        <ul>          <li>Office</li>          <li>Excel</li>          <li>Word</li>          <li>Powerpoint</li>        </ul>      </ul>    </li>    <li>MacBook</li>  </ul></body>  </html>
Output:
Complex Nested Unordered List
Supported Browsers: 
Google Chrome
Internet Explorer
Microsoft Edge
Firefox
Safari
Opera
arorakashish0911
shubhamyadav4
bhaskargeeksforgeeks
HTML-Tags
HTML
Web Technologies
HTML
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Swapping two array elements in a single line using JavaScript

15 Mar, 2021
In JavaScript, there exist many ways using by which one can swap two array elements. In this article, we will discuss a way in which one can swap two array elements in JavaScript in a single line. The input and output would be as follows.
Input: arr = { 10, 20, 40, 30 }
Output: arr = { 10, 20, 30, 40 } 
// Swapped 30 and 40
This swapping can be done by writing the 2 array elements we want to reverse in order and in square brackets on the left-hand side. On the right-hand side we will write the same array elements but this time in reverse order.
Syntax:
[a[m], a[n]] = [a[n], a[m]] 
 
// where m and n are the index numbers to swap
Example 1:
Javascript
<script>  let arr = [1, 2, 3, 5, 4];    // Swapping element at index 3 with index 4  [arr[3], arr[4]] = [arr[4], arr[3]]    // Print the array  console.log(arr)</script>
Output:
[1, 2, 3, 4, 5]
Example 2:
Javascript
<script>  let arr = ["e", "b", "c", "d", "a"];    // Swapping element at index 0 with index 4  [arr[0], arr[4]] = [arr[4], arr[0]];    // Print the array  console.log(arr);</script>
Output:
['a','b','c','d','e']
javascript-array
JavaScript-Questions
JavaScript
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Java String startsWith() and endsWith() Methods With Examples

30 Sep, 2021
The String class in Java is an immutable and non-primitive data type that is used to store the characters of the sequence. The string is non-primitive datatype because, during the initialization of the string variable, it refers to an object that contains methods that can perform several different kinds of operations, but according to the definition of the primitive datatype, they are not considered as the object and store the data in the stack memory. In this article, we will discuss the endWith() method and the startsWith() method of the String class in java.
Let us discuss both the methods individually:
enWith() Method in javastartWith() Method
enWith() Method in java
startWith() Method
Method 1: endsWith() method 
This method of the String class checks whether the given string ends with the specified string suffix or not.
Syntax:
endsWith(String suffix)     
Parameter: This method takes one parameter that is of string type..
Return type: This method returns a boolean value true or false. the i.e string ends with a specified suffix or not.
Example:
Java
// Java Program to illustrate endWith() Method // Importing required classesimport java.io.*; // Main classclass GFG {     // Main driver method    public static void main(String[] args)    {        // Given String        String first = "Geeks for Geeks";         // Suffix to be matched        String suffix = "kse";         // Given String does not end with        // the above suffix hence return false        System.out.println(first.endsWith(suffix));         // Changing the suffix say        // it be customly 's'        suffix = "s";         // Given String ends with the given suffix  hence        // returns true        System.out.println(first.endsWith(suffix));    }}
false
true
Method 2: startsWith() method
This method of the String class checks whether the given string starts with the specified string prefix or not.
Syntax: 
startsWith(String prefix)     
Parameter: This method takes one parameter that is of string type..
Return type: This method returns a boolean value true or false. the i.e string ends with a specified prefix or not.
Examples: 
Java
// Java Program to illustrate startWith() Method // Importing required classesimport java.io.*; // Main classclass GFG {     // Main driver method    public static void main(String[] args)    {        // Given String        String first = "Geeks for Geeks";         // Prefix to be matched        String prefix = "se";         // Given String does not start with the above prefix        // hence return false        System.out.println(first.startsWith(prefix));         // Changing the prefix        prefix = "Gee";         // Given String starts with the given prefix hence        // returns true        System.out.println(first.startsWith(prefix));    }}
false
true
 
varshagumber28
saurabh1990aror
Java-Strings
Picked
Java
Java-Strings
Java
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python – Get the indices of all occurrences of an element in a list

28 Nov, 2021
Given a list, the task is to write a Python Program to get the indices of all occurrences of an element in a list.
This is a simple method to get the indices of all occurrences of an element in a list. Here we use a for-loop to iterate through each element in the original list.
Syntax : for iterator_name in range(length)
where
iterator_name is the name of the iterator
length is the size of the list
Example : 
Python3
# initialize a listmy_list = [1, 2, 3, 1, 5, 4]  # find length of the listlist_size = len(my_list)    # declare for loopfor itr in range(list_size):            # check the condition    if(my_list[itr] == 1):                    # print the indices        print(itr)  
Output:
0
3
Instead of using for-loop we can use enumerate function. This function adds a counter to an iterable and returns the enumerate object.
Syntax: [expression for element_name in enumerate(list_name) if condition]
where
Element_name is the name of the element
list_name is the name of the list
Condition is the condition that needs to be true
For this, we will create list and then we will create enumerate function to get indices of all occurrences of an element in a list
Example :
Python3
# initialize a listmy_list = [1, 2, 3, 1, 5, 4]  indices = [ind for ind, ele in enumerate(my_list) if ele == 1]  # print the indicesprint(indices)  
Output:
[0, 3]
Itertools is memory-efficient tools that are useful by themselves or in combination, so for this we will use count() methods from this module which will return an iterator of evenly spaced values from the start value.
Syntax: [expression for element_name in zip(count(), list_name) if condition]
element_name is the name of the element
list_name is the name of the list
Condition is the condition that needs to be true
For this, we will create a list and then using comprehension with zip() we will get indices of all occurrences of an element in a list. 
Example: 
Python3
# import count method from itertoolsfrom itertools import count    # initialize a listmy_list = [1, 2, 3, 1, 5, 4] indices = [ind for ind,            ele in zip(count(),                      my_list) if ele == 1]  # print the indicesprint(indices)  
Output:
[0, 3]
NumPy is general-purpose array-processing package, it provides convenient ways to use arrays in Python. 
Syntax: numpy.where(list_name,value)[index]
where 
list_name is the name of the list
Value is the value to be searched for
Index is the starting index of array (usually it will be “0”)
For this, we will create an array using numpy.array() and then get all the indices of elements in an input array when the condition is satisfied using numpy.where() methods.
Example : 
Python3
# import numpy moduleimport numpy    # initialize a arraymy_list = numpy.array([1, 2, 3, 1, 5, 4])  indices = numpy.where(my_list == 1)[0]  # display resultprint(indices)  
Output :
[0, 3]
Picked
Python list-programs
python-list
Python
Python Programs
python-list
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python | Sort given list by frequency and remove duplicates

11 May, 2020
Problems associated with sorting and removal of duplicates is quite common in development domain and general coding as well. The sorting by frequency has been discussed, but sometimes, we even wish to remove the duplicates without using more LOC’s and in a shorter way. Let’s discuss certain ways in which this can be done.
Method #1 : Using count() + set() + sorted()
The sorted function can be used to sort the elements as desired, the frequency can be computed using the count function and removal of duplicates can be handled using the set function.
# Python3 code to demonstrate# sorting and removal of duplicates# Using sorted() + set() + count()  # initializing listtest_list = [5, 6, 2, 5, 3, 3, 6, 5, 5, 6, 5]  # printing original listprint("The original list : " + str(test_list))  # using sorted() + set() + count()# sorting and removal of duplicatesres = sorted(set(test_list), key = lambda ele: test_list.count(ele))  # print resultprint("The list after sorting and removal : " + str(res))
The original list : [5, 6, 2, 5, 3, 3, 6, 5, 5, 6, 5]
The list after sorting and removal : [2, 3, 6, 5]

 
Method #2 : Using Counter.most_common() + list comprehension
If one has a particular use case of sorting by the decreasing order of frequency, one can also use most-common function of Counter library to get frequency part.
# Python3 code to demonstrate# sorting and removal of duplicates# Using Counter.most_common() + list comprehensionfrom collections import Counter  # initializing listtest_list = [5, 6, 2, 5, 3, 3, 6, 5, 5, 6, 5]  # printing original listprint("The original list : " + str(test_list))  # using Counter.most_common() + list comprehension# sorting and removal of duplicatesres = [key for key, value in Counter(test_list).most_common()]  # print resultprint("The list after sorting and removal : " + str(res))
The original list : [5, 6, 2, 5, 3, 3, 6, 5, 5, 6, 5]
The list after sorting and removal : [5, 6, 3, 2]

Python list-programs
Python-sort
Python
Python Programs
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
PHP | str_pad() Function

22 Mar, 2018
The str_pad() function is a built-in function in PHP and is used to pad a string to a given length. We can pad the input string by any other string up to a specified length. If we do not pass the other string to the str_pad() function then the input string will be padded by spaces.
Syntax :
string str_pad($string, $length, $pad_string, $pad_type)
Parameters: This function accepts four parameters as shown in the above syntax out of which first two are mandatory to be supplied and rest two are optional. All of these parameters are described below:
$string: This parameter is mandatory. It specifies the input string which is needed to be padded.
$length: This parameter is also mandatory. It specifies the length of the new string that will be generated after padding the input string $string. If this length is less than or equals the length of input string then no padding will be done.
$pad_string: This parameter is optional and its default value is whitespace ‘ ‘. It specifies the string to be used for padding.
$pad_type: This parameter is also optional. It specifies which side of the string needs to be padded, i.e. left, right or both. By default it’s value is set to STR_PAD_RIGHT. If we want to pad the left side of the input string then we should set this parameter to STR_PAD_LEFT and if we want to pad both sides then this parameter should be set to STR_PAD_BOTH.
Return Value: This parameter returns a new string obtained after padding the input string $string.
Examples:
Input : $string = "Hello World", $length = 20, 
        $pad_string = "."
Output : Hello World........

Input : $string = "Geeks for geeks", $length = 18,
        $pad_string = ")"
Output : Geeks for geeks)))

Below programs illustrate the str_pad() function in PHP:
Program 1: In this program we will pad to both the sides of the input string by setting last parameter to STR_PAD_BOTH. If the padding length is not an even number, the right side gets the extra padding.
<?php   $str = "Geeks for geeks";   echo str_pad($str, 21, ":-)", STR_PAD_BOTH); ?>
Output:
:-)Geeks for geeks:-)

Program 2: In this program we will pad to left side of the input string by setting last parameter to STR_PAD_LEFT.
<?php   $str = "Geeks for geeks";   echo str_pad($str, 25, "Contribute", STR_PAD_LEFT); ?>
Output:
ContributeGeeks for geeks

Program 3: In this program we will pad to right side of the input string by setting last parameter to STR_PAD_RIGHT.
<?php   $str = "Geeks for geeks";   echo str_pad($str, 26, " Contribute", STR_PAD_RIGHT); ?>
Output:
Geeks for geeks Contribute

Reference:http://php.net/manual/en/function.str-pad.php
PHP-string
PHP
Web Technologies
PHP
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
strspn() function in C

02 Oct, 2017
The strspn() function returns the length of the initial substring of the string pointed to by str1 that is made up of only those character contained in the string pointed to by str2.
Syntax :
size_t strspn(const char *str1, const char *str2)
str1 : string to be scanned.
str2 : string containing the 
characters to match.
Return Value : This function
returns the number of characters
in the initial segment of str1 
which consist only of characters 
from str2.
   // C program to illustrate strspn() function#include <stdio.h>#include <string.h>  int main () {   int len = strspn("geeks for geeks","geek");   printf("Length of initial segment matching : %d\n", len );       return(0);}
Output:
Length of initial segment matching 4
   // C program to illustrate strspn() function#include <stdio.h>#include <string.h>  int main () {   int len = strspn("i am","xyz");   printf("Length of initial segment matching : %d\n", len );   return(0);}
Output:
Length of initial segment matching 0
This article is contributed by Shivani Ghughtyal. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
C-Library
C-String
C Language
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Find columns and rows with NA in R DataFrame

26 Mar, 2021
A data frame comprises cells, called data elements arranged in the form of a table of rows and columns. A data frame can have data elements belonging to different data types as well as missing values, denoted by NA. 
Approach
Declare data frame
Use function to get values to get NA values
Store position
Display result
The following in-built functions in R collectively can be used to find the rows and column pairs with NA values in the data frame. The is.na() function returns a logical vector of True and False values to indicate which of the corresponding elements are NA or not. This is followed by the application of which() function which indicates the position of the data elements. The following code snippet can be used to find such element index positions.
Syntax:
which(is.na(dataframe), arr.ind=TRUE)
Example:
R
# declaring data framedata_frame = data.frame(col1 = c(1,NA),col2 = c(7:8),col3 = c(NA,NA))  # printing original data frameprint ("Original Data Frame")print(data_frame)  # extracting positions of NA valuesprint ("Row and Col positions of NA values")which(is.na(data_frame), arr.ind=TRUE)
Output
[1] "Original Data Frame"
 col1 col2 col3
1    1    7   NA
2   NA    8   NA
[1] "Row and Col positions of NA values"
    row col
[1,]   2   1
[2,]   1   3
[3,]   2   3
In case, we don’t specify arr,ind=TRUE as an argument, then the element number counting row wise is returned. 
Example:
R
# declaring data framedata_frame = data.frame(col1 = c("A",NA,"B"),col2 = c(100:102),col3 = c(NA,NA,9))  # printing original data frameprint ("Original Data Frame")print(data_frame)  # finding NA values beginning with row1 and col1 as the# first element. Rows2 and col2 is second element.print ("Row and Col positions of NA values")which(is.na(data_frame))
Output
[1] "Original Data Frame"
 col1 col2 col3
1    A  100   NA
2 <NA>  101   NA
3    B  102    9
[1] "Row and Col positions of NA values"
[1] 2 7 8
The missing values can also be individually be computed within a column, by accessing the specific column of the dataframe using the dataframe$colname as an argument in the above code snippet. In case no NA values are present in a specific column, integer(0) is returned as an output. 
Example:
R
# declaring data framedata_frame = data.frame(col1 = c("A",NA,"B"),col2 = c(100:102),col3 = c(NA,NA,9))  # printing original data frameprint ("Original Data Frame")print(data_frame)  # extracting positions of NA valuesprint ("NA values in column 1")which(is.na(data_frame$col1), arr.ind=TRUE)  # extracting positions of NA valuesprint ("NA values in column 2")which(is.na(data_frame$col2), arr.ind=TRUE)
Output
 [1] "Original Data Frame"
 col1 col2 col3
1    A  100   NA
2 <NA>  101   NA
3    B  102    9
[1] "NA values in column 1"
[1] 2
[1] "NA values in column 2"
integer(0)
Picked
R DataFrame-Programs
R-DataFrame
R Language
R Programs
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to create frequency table of data.table in R?

If we have an data.table object or a data frame converted to a data.table and it has a factor column then we might want to create a frequency table that shows the number of values each factor has or the count of factor levels. This is a data summarization method which helps us to understand the variation in the occurrences of factor levels. This can be easily done with a single line of code if we have a data.table object, otherwise we first need to convert the object.
Consider the below data frame −
 Live Demo
Group<-sample(c("A","B","C","D"),20,replace=TRUE)
Frequency<-sample(1:50,20)
df1<-data.frame(Group,Frequency)
df1
 Group Frequency
1   A    11
2   B    19
3   A    41
4   D    24
5   A    22
6   B    26
7   C    46
8   C    4
9   A    45
10  C    44
11  A    50
12  C    20
13  B    27
14  D    12
15  A    34
16  B    6
17  C    35
18  D    32
19  A    42
20  D    30
Loading data.table package and reading the data frame df1 as data.table −
library(data.table)
df1<-as.data.table(df1)
Finding the frequency table of df1 which is a data.table object now −
df1[,.N,by=Group]
 Group N
1: A   7
2: B   4
3: D   4
4: C   5
Let’s have a look at another example −
 Live Demo
Class<-sample(c("1","2","3","4","5"),20,replace=TRUE)
Scores<-sample(1:100,20)
df2<-data.frame(Class,Scores)
df2
 Class Scores
1  2    45
2  5    66
3  4    61
4  5    96
5  3    27
6  5    94
7  5    51
8  3    98
9  1    14
10 3    83
11 3    6
12 1    16
13 1    18
14 1    35
15 2    70
16 4    67
17 1    63
18 5    31
19 1    58
20 4    15
df2<-as.data.table(df2)
df2[,.N,by=Class]
 Class N
1: 2   2
2: 5   5
3: 4   3
4: 3   4
5: 1   6
Bootstrap .radio-inline class

Use .radio-inline class to a series of radios for controls to appear on the same line. You can try to run the following code to implement the radio-inline class in Bootstrap −
Live Demo
<!DOCTYPE html>
<html>
   <head>
      <title>Bootstrap Forms</title>
      <meta name = "viewport" content = "width=device-width, initial-scale = 1">
      <link rel = "stylesheet" href = "https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css">
      <script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
      <script src = "https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
   </head>
   <body>
      <label for = "name">Best Porgraming Language</label>
      <div>
         <label class = "radio-inline">
            <input type = "radio" name = "optionsRadiosinline" id = "optionsRadios3" value = "option1" checked> Java
         </label>
         <label class = "radio-inline">
            <input type = "radio" name = "optionsRadiosinline" id = "optionsRadios4" value = "option2"> C
         </label>
         <label class = "radio-inline">
            <input type = "radio" name = "optionsRadiosinline" id = "optionsRadios4" value = "option3"> C++
         </label>
      </div>
   </body>
</html>