code-rag-bench/online-tutorials huggingface dataset:
How do I write class names in Java?

While writing class names you need to keep the following points in mind.
You shouldn’t use predefined or existing class names as the name of the current class.
You shouldn’t use any Java keywords as class name (with the same case).
The First letter of the class name should be capital and remaining letters should be small (mixed case).
class Sample

Likewise, first letter of each word in the name should be capital an remaining letters should be small.
class Test

Keeping interface names simple and descriptive is suggestable.
Better not to use acronyms while writing class names.
 Live Demo
public class Test {
   public void sample() {
      System.out.println("This is sample method");   
   }
   public void demo() {
      System.out.println("This is demo method");   
   }
   public static void main(String args[]) {
      Test obj = new Test();
      obj.sample();
      obj.demo();
   }
}
This is sample method
This is demo method
Dividing two lists in Python

The elements in tow lists can be involved in a division operation for some data manipulation activity using python. In this article we will see how this can be achieved.
The zip function can pair up the two given lists element wise. The we apply the division mathematical operator to each pair of these elements. Storing the result into a new list.
 Live Demo
# Given lists
list1 = [12,4,0,24]
list2 = [6,3,8,-3]

# Given lists
print("Given list 1 : " + str(list1))
print("Given list 2 : " + str(list2))

# Use zip
res = [i / j for i, j in zip(list1, list2)]

print(res)
Running the above code gives us the following result −
Given list 1 : [12, 4, 0, 24]
Given list 2 : [6, 3, 8, -3]
[2.0, 1.3333333333333333, 0.0, -8.0]
The truediv operator is a part of python standard library called operator. It performs the true division between the numbers. We also use the map function to apply the division operator iteratively for each pair of elements in the list.
 Live Demo
from operator import truediv
# Given lists
list1 = [12,4,0,24]
list2 = [6,3,8,-3]

# Given lists
print("Given list 1 : " + str(list1))
print("Given list 2 : " + str(list2))

# Use zip
res = list(map(truediv, list1, list2))

print(res)
Running the above code gives us the following result −
Given list 1 : [12, 4, 0, 24]
Given list 2 : [6, 3, 8, -3]
[2.0, 1.3333333333333333, 0.0, -8.0]
With JavaScript how to change the width of a table border?

To change the width of a table border, use the DOM border property. You can try to run the following code to change the width of a table border in JavaScript −
<!DOCTYPE html>
<html>
   <head>
      <script>
         function borderFunc(x) {
            document.getElementById(x).style.border = "5px dashed blue";
         }
      </script>
   </head>
 
   <body>
      <table style = "border:2px solid black" id = "newtable">
         <tr>
            <td>One</td>
            <td>Two</td>
         </tr>
         <tr>
            <td>Three</td>
            <td>Four</td>
         </tr>
         <tr>
            <td>Five</td>
            <td>Six</td>
         </tr>
      </table>
      <p>
         <input type = "button" onclick = "borderFunc('newtable')"
         value = "Change Border Width">
      </p>
   </body>
</html>
VBA - Space

The Space function fills a string with a specific number of spaces.
space(number)

Number − A required parameter. The number of spaces that we want to add to the given string.
Private Sub Constant_demo_Click()
   Dim var1 as Variant
   
   var1 = "Microsoft"
   Dim var2 as Variant
   
   var2 = "VBScript"
   msgbox(var1 & Space(2)& var2)
End Sub
When you execute the above function, it produces the following output.
Microsoft VBScript


    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
Java Program to convert String to Double

To convert String to Double in Java, you can use the following three examples. Two of them are using in-built methods parseDouble() and valueOf(). However, one of the method isn’t using a method.
Let us work through them one by one.
The following is an example to convert String to Double without using a method −
 Live Demo
public class Demo {
    public static void main(String args[]) {
       Double val = new Double("88.77");
       System.out.println(val);
    }
}
88.77
The following is another example to convert String to Double. Here, we will use parseDouble() method −
 Live Demo
public class Demo {
    public static void main(String args[]) {
       double val = Double.parseDouble("11.89");
       System.out.println(val);
    }
}
11.89
Let us see an example to convert String to Double using valueOf() method −
 Live Demo
public class Demo {
    public static void main(String args[]) {
       Double val = Double.valueOf("299.9");
       System.out.println(val);
    }
}
299.9
What are Closures in Lua Programming?

In Lua, any function is a closure. In a narrower sense, a closure is an anonymous function like the returned function in your example.
Closures are first-class: they can be assigned to variables, passed to functions and returned from them. They can be both keys and values in Lua tables.
Unlike C++ or PHP, closures in Lua have access to all variables in local scope— upvalues with no need to declare upvalues explicitly. Upvalues survive when code execution leaves the block where they were set.
Now that we know what a closure is and why it is useful, let’s take an example and see how it works.
Consider the example shown below −
 Live Demo
function simpleCounter()
   local i = 0
   return function () -- anonymous function
      i = i + 1
         return i
      end
   end
c1 = simpleCounter()
   print(c1()) --> 1
   print(c1()) --> 2
c2 = simpleCounter()
   print(c2()) --> 1
   print(c1()) --> 3
   print(c2()) --> 2
1
2
1
3
2
Binary literals in C++14 with Examples - GeeksforGeeks

28 Jan, 2021
In this article, we will discuss Binary literals in C++14.
While writing programs which involve mathematical evaluations or various types of number, we usually like to specify each digit type with specific prefix i.e., For Hexadecimal number use the prefix ‘0x’ and for Octal number use the prefix ‘0’. Below is the program to illustrate the same:
Program 1:
C++14
// C++ program to illustrate the// Hexadecimal and Octal number// using literals#include <iostream>using namespace std;  // Driver Codeint main(){    // Hexadecimal number with    // prefix '0x'    int h = 0x13ac;      // Octal number with prefix '0'    int o = 0117;      // Print the number of the    // hexadecimal form    cout << h << endl;      // Print the number of the    // octal form    cout << o;      return 0;}
5036
79

Binary Literals: In the above way like in hexadecimal and octal numbers, now we can directly write binary literals (of the form 0’s and 1’s) in C++14. The binary number can be expressed as 0b or 0B as the prefix. Below is the program to illustrate the same:
Program 2:
C++14
// C++ program to illustrate the// binary number using literals#include <iostream>using namespace std;  // Driver Codeint main(){    // Binary literal with prefix '0b'    int a = 0b00001111;      cout << a << '\n';      // Binary literal with prefix '0B'    int b = 0B00001111;    cout << b;      return 0;}
15
15

Technical Scripter 2020
C++
C++ Programs
Technical Scripter
CPP
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Operator Overloading in C++
Polymorphism in C++
Friend class and function in C++
Iterators in C++ STL
Sorting a vector in C++
Header files in C/C++ and its uses
C++ Program for QuickSort
How to return multiple values from a function in C or C++?
Program to print ASCII Value of a character
CSV file management using C++
What happens if we re-declare a variable in JavaScript?

On re-declaring a variable in JavaScript, the variable value still remains the same.
Let’s see an example. Here, we are declaring the variable age −
<html>
   <body>
      <script>
         <!--
            var age = 20;
            var age;
            if( age > 18 ){
               document.write("Qualifies for driving");
            }
           //-->
      </script>
   </body>
</html>
Create red neon glow shadow using CSS

To create red neon glow shadow, use the text-shadow property. You can try to run the following code to achieve this
Live Demo
<!DOCTYPE html>
<html>
   <head>
      <style>
         h1 {
            text-shadow: 0 0 4px #FF0000;
         }
      </style>
   </head>
   <body>
      <h1>Heading One</h1>
      <p>Above heading has a read neon glow shadow effect.</p>
   </body>
</html>
Can't find my.ini in MySQL directory?

The my.ini is in hidden folder of program data. First go to C: drive and then hidden folder of program data. From that, move to the MySQL version directory.
Here is the snapshot of the C: drive −
Click on C drive. The snapshot is as follows. Here, you can see the Program Data folder −
Now go to MySQL under Program Data folder. The snapshot is as follows −
Go to MySQL version. The snapshot is as follows −
Note − Here, we are using MySQL version 8.0.12
Here is the my.ini file.
In order to reach the location, you can also use the following command −
mysql> select @@datadir;
The following is the output −
+---------------------------------------------+
| @@datadir                                   |
+---------------------------------------------+
| C:\ProgramData\MySQL\MySQL Server 8.0\Data\ |
+---------------------------------------------+
1 row in set (0.00 sec)
MongoDB Insert() Method - db.Collection.insert() - GeeksforGeeks

28 Jan, 2021
In MongoDB, the insert() method inserts a document or documents into the collection. It takes two parameters, the first parameter is the document or array of the document that we want to insert and the remaining are optional.
Using this method you can also create a collection by inserting documents.
You can insert documents with or without _id field. If you insert a document in the collection without _id field, then MongoDB will automatically add an _id field and assign it with a unique ObjectId. And if you insert a document with _id field, then the value of the _id field must be unique to avoid the duplicate key error.
This method can also be used inside multi-document transactions.
Syntax:
db.Collection_name.insert(
<document or [document1, document2,...]>,
{
    writeConcern: <document>,
    ordered: <boolean>
})
Parameters:
The first parameter is the document or an array of documents. Documents are a structure created of file and value pairs, similar to JSON objects.
The second parameter is optional.
Optional Parameters:
writeConcern: It is only used when you do not want to use the default write concern. The type of this parameter is a document.
ordered: The default value of this parameter is true. If it is true, it inserts documents in the ordered manner. Otherwise, it randomly inserts documents.
Return:
This method returns WriteResult when you insert single document in the collection.
This method returns BulkWriteResult when you insert multiple documents in the collection.
Examples:
In the following examples, we are working with:
Database: gfg
Collection: student
Document: No document but, we want to insert in the form of the student name and student marks.
Here, we insert a document in the student collection whose name is Akshay and marks is 500 using insert() method.
db.student.insert({Name: "Akshay", Marks: 500})
Output:
Here, we insert multiple documents in the collection by passing an array of documents in the insert method.
db.student.insert([{Name: "Bablu", Marks: 550}, 
           {Name: "Chintu", Marks: 430},
                   {Name: "Devanshu", Marks: 499}])
Output:
Here, we insert a document in the student collection with _id field.
db.student.insert({_id: 102,Name: "Anup", Marks: 400})
Output:
MongoDB-method
Picked
MongoDB
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Aggregation in MongoDB
Spring Boot JpaRepository with Example
Mongoose Populate() Method
MongoDB - db.collection.Find() Method
MongoDB - Check the existence of the fields in the specified collection
How to build a basic CRUD app with Node.js and ReactJS ?
Upsert in MongoDB
Mongoose | findById() Function
How to connect MongoDB with ReactJS ?
MongoDB - Distinct() Method
Python Syntax

As we learned in the previous page, Python syntax can be executed by writing directly in the Command Line:
Or by creating a python file on the server, using the .py file extension, and running it in the Command Line:
Indentation refers to the spaces at the beginning of a code line.
Where in other programming languages the indentation in code is for readability 
only, the indentation in Python is very important.
Python uses indentation to indicate a block of code.
Python will give you an error if you skip the indentation:
Syntax Error:
The number of spaces is up to you as a programmer, the most common use is four, but it has 
to be at least one.
You have to use the same number of spaces in the same block of code, 
otherwise Python will give you an error:
Syntax Error:
In Python, variables are created when you assign a value to it:

Variables in Python:
Python has no command for declaring a variable.
You will learn more about variables in the 
Python Variables chapter.
Python has commenting capability for the purpose of in-code documentation.
Comments start with a #, and Python will render the rest of the line as a comment:

Comments in Python:
Insert the missing part of the code below to output "Hello World".
("Hello World")

Start the Exercise
We just launchedW3Schools videos
Get certifiedby completinga course today!
If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail:
help@w3schools.com
Your message has been sent to W3Schools.
How to subtract one data frame from another in R?

If we have two data frames with same number of columns of same data type and equal number of rows then we might want to find the difference between the corresponding values of the data frames. To do this, we simply need to use minus sign. For example, if we have data-frames df1 and df2 then the subtraction can be found as df1-df2.
Consider the below data frame −
 Live Demo
x1<-rpois(20,5)
x2<-rpois(20,8)
df1<-data.frame(x1,x2)
df1
x1 x2
1 8 9
2 3 10
3 5 4
4 3 10
5 6 4
6 4 11
7 6 4
8 4 14
9 8 13
10 5 8
11 7 7
12 8 9
13 3 4
14 6 12
15 3 9
16 11 10
17 3 4
18 5 10
19 10 7
20 7 10
 Live Demo
y1<-sample(0:10,20,replace=TRUE)
y2<-sample(0:10,20,replace=TRUE)
df2<-data.frame(y1,y2)
df2
y1 y2
1 6 9
2 0 3
3 2 5
4 7 6
5 2 9
6 8 3
7 4 9
8 4 1
9 4 1
10 1 2
11 3 0
12 5 7
13 3 4
14 1 6
15 8 8
16 6 9
17 7 3
18 9 4
19 5 0
20 9 8
Subtracting df2 from df1 −
df1-df2
x1 x2
1 5 2
2 6 4
3 2 6
4 0 -4
 5 2 0
6 1 3
7 2 -2
8 3 11
9 1 5
10 5 1
11 0 4
12 -5 -3
13 3 7
14 2 -3
15 -3 8
16 2 2
17 3 6
18 -6 7
19 -1 4
20 2 -2
Let’s have a look at another example −
Subtracting df2 from df1 −
 Live Demo
V1<-rpois(20,1)
V2<-rpois(20,10)
V3<-rpois(20,12)
df_V<-data.frame(V1,V2,V3)
df_V
V1 V2 V3
1 0 6 13
2 3 9 13
3 1 9 14
4 3 12 10
5 1 11 4
6 1 5 11
7 1 5 17
8 1 9 7
9 2 14 13
10 1 4 16
11 0 8 9
12 1 6 9
13 3 12 3
14 1 11 18
15 1 5 13
16 0 13 12
17 1 11 12
18 1 9 6
19 0 10 12
20 0 10 13
 Live Demo
W1<-sample(0:5,20,replace=TRUE)
W2<-sample(0:10,20,replace=TRUE)
W3<-sample(0:15,20,replace=TRUE)
df_W<-data.frame(W1,W2,W3)
df_W
W1 W2 W3
1 0 8 14
2 3 2 5
3 3 2 10
4 0 1 9
5 1 9 8
6 1 5 12
7 3 2 13
8 1 9 7
9 0 5 2
10 1 9 12
11 3 1 0
12 4 10 0
13 4 2 0
14 4 4 13
15 5 3 15
16 2 6 0
17 4 1 14
18 0 7 10
19 1 4 15
20 2 0 15
Subtracting df_W from df_V −
df_V-df_W
V1 V2 V3
1 -5 5 12
2 -3 12 7
3 0 10 7
4 -1 9 14
5 -2 6 17
6 2 -2 4
7 0 7 5
8 0 2 -1
9 -1 6 -4
10 -2 5 -4
11 -3 0 7
12 -2 11 -4
13 -3 2 -1
14 0 3 - 3
15 -1 7 2
16 2 2 9
17 -3 6 2
18 -2 -2 -1
19 2 6 14
20 -3 10 4
Python | Pandas Series.reset_index()

10 Feb, 2019
Pandas series is a One-dimensional ndarray with axis labels. The labels need not be unique but must be a hashable type. The object supports both integer- and label-based indexing and provides a host of methods for performing operations involving the index.
Pandas Series.reset_index() function generate a new DataFrame or Series with the index reset. This comes handy when index is need to be used as a column.
Syntax: Series.reset_index(level=None, drop=False, name=None, inplace=False)
Parameter :level : For a Series with a MultiIndexdrop : Just reset the index, without inserting it as a column in the new DataFrame.name : The name to use for the column containing the original Series values.inplace : Modify the Series in place
Returns : result : Series
Example #1: Use Series.reset_index() function to reset the index of the given Series object.
# importing pandas as pdimport pandas as pd  # Creating the Seriessr = pd.Series([10, 25, 3, 11, 24, 6])  # Create the Indexindex_ = ['Coca Cola', 'Sprite', 'Coke', 'Fanta', 'Dew', 'ThumbsUp']  # set the indexsr.index = index_  # Print the seriesprint(sr)
Output :
Now we will use Series.reset_index() function to reset the index of the given series object.
# reset the indexresult = sr.reset_index()  # Print the resultprint(result)
Output :As we can see in the output, the Series.reset_index() function has reset the index of the given Series object to default. It has preserved the index and it has converted it to a column. Example #2: Use Series.reset_index() function to reset the index of the given Series object. Do not keep the original index labels of the given series object.
# importing pandas as pdimport pandas as pd  # Creating the Seriessr = pd.Series([10, 25, 3, 11, 24, 6])  # Create the Indexindex_ = ['Coca Cola', 'Sprite', 'Coke', 'Fanta', 'Dew', 'ThumbsUp']  # set the indexsr.index = index_  # Print the seriesprint(sr)
Output :
Now we will use Series.reset_index() function to reset the index of the given series object and also we will be dropping the original index labels.
# reset the indexresult = sr.reset_index(drop = True)  # Print the resultprint(result)
Output :As we can see in the output, the Series.reset_index() function has reset the index of the given Series object to default. It has dropped the original index.
Python pandas-series
Python pandas-series-methods
Python-pandas
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Prototypal Inheritance using __proto__ in JavaScript

02 Jun, 2020
Every object with its methods and properties contains an internal and hidden property known as [[Prototype]]. The Prototypal Inheritance is a feature in javascript used to add methods and properties in objects. It is a method by which an object can inherit the properties and methods of another object. Traditionally, in order to get and set the [[Prototype]] of an object, we use Object.getPrototypeOf and Object.setPrototypeOf. Nowadays, in modern language, it is being set using __proto__.
Syntax:
ChildObject.__proto__ = ParentObject
Example In the given example, there are two objects ‘person’ and ‘GFGuser’. The object ‘GFGuser’ inherits the methods and properties of the object ‘person’ and further uses them.
<!DOCTYPE html><html lang="en">    <head>        <meta charset="UTF-8" />        <title>prototype</title>    </head>    <body>        <script>            // object person            let person = {                talk: true,                Canfly() {                    return "Sorry, Can't fly";                },            };            // Object GFGuser            let GFGuser = {                CanCode: true,                CanCook() {                    return "Can't say";                },                              //  Inheriting the properties and methods of person                __proto__: person,             };              // Printing on console            // Property of person            console.log("Can a GFG User talk: " + GFGuser.talk);                         // Method of person            console.log("Can a GFG User fly: " + GFGuser.Canfly());                         // Property of GFGuser            console.log("Can a GFG User code: " + GFGuser.CanCode);                         // Method of GFGuser            console.log("Can a GFG User cook: " + GFGuser.CanCook());         </script>    </body></html>
Output
JavaScript-Misc
JavaScript
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
Remove elements from a JavaScript Array
Difference Between PUT and PATCH Request
Roadmap to Learn JavaScript For Beginners
JavaScript | Promises
Installation of Node.js on Linux
Top 10 Projects For Beginners To Practice HTML and CSS Skills
Difference between var, let and const keywords in JavaScript
How to insert spaces/tabs in text using HTML/CSS?
How to fetch data from an API in ReactJS ?
How to limit the number of characters entered in a textarea in an HTML form?

To add a multi-line text input, use the HTML <textarea> tag. You can set the size of a text area using the cols and rows attributes. To limit the number of characters entered in a textarea, use the maxlength attribute. The value if the attribute is in number.
Here are the other attributes of <textarea> tag −
 
You can try to run the following code to limit the number of characters entered in textarea in an HTML form −
<!DOCTYPE html>
<html>
   <head>
      <title>HTML textarea Tag</title>
   </head>

   <body>
      <form action = "" method = "get">
         What improvements you want in College?
         <br>
      
         <textarea rows = "5" cols = "40" maxlength = "100" name = "description">
            Enter answer here...
         </textarea>
         <br>
         
         <input type = "submit" value = "submit" />
      </form>
      
   </body>
</html>
TypeScript - Array reduce()

reduce() method applies a function simultaneously against two values of the array (from left-to-right) as to reduce it to a single value.
array.reduce(callback[, initialValue]);

callback − Function to execute on each value in the array.
callback − Function to execute on each value in the array.
initialValue − Object to use as the first argument to the first call of the callback.
initialValue − Object to use as the first argument to the first call of the callback.
Returns the reduced single value of the array.
var total = [0, 1, 2, 3].reduce(function(a, b){ return a + b; }); 
console.log("total is : " + total );

On compiling, it will generate the same code in JavaScript.
Its output is as follows −
total is : 6
GATE | GATE CS 2012 | Question 4

28 Jun, 2021
Assuming P != NP, which of the following is true ?
(A) NP-complete = NP
(B) NP-complete  P = 
(C) NP-hard = NP
(D) P = NP-complete

(A) A(B) B(C) C(D) DAnswer: (B)Explanation:
The answer is B (no NP-Complete problem can be solved in polynomial time). Because, if one NP-Complete problem can be solved in polynomial time, then all NP problems can solved in polynomial time. If that is the case, then NP and P set become same which contradicts the given condition.
Related Article:NP-Completeness | Set 1 (Introduction)P versus NP problem (Wikipedia)Quiz of this Question
GATE-CS-2012
GATE-GATE CS 2012
GATE
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
GATE | GATE-CS-2014-(Set-2) | Question 65
GATE | Sudo GATE 2020 Mock I (27 December 2019) | Question 33
GATE | GATE CS 2008 | Question 40
GATE | GATE-CS-2014-(Set-3) | Question 65
GATE | GATE CS 2008 | Question 46
GATE | GATE-CS-2015 (Set 3) | Question 65
GATE | GATE CS 2011 | Question 49
GATE | GATE CS 1996 | Question 38
GATE | GATE-CS-2004 | Question 31
GATE | GATE IT 2006 | Question 20
Is it possible to assign a reference to "this" in java?

The "this" keyword in Java is used as a reference to the current object, within an instance method or a constructor. Using it, you can refer the members of a class such as constructors, variables, and methods.
According to the definition "this" is a keyword which acts as a reference to the current object (the object from whose constructor/method you are using it), its value id is fixed. Therefore, you cannot assign a new reference value to it. Moreover, it is just a keyword, not a variable.
Still, if you try to it assign a reference value to "this" it leads to a compilation error.
In the following Java program, the class (ExampleClass) has two private variables name, age and, a parameterized constructor which instantiates these variables. From a method named display, we are trying to assign a new value to "this".
 Live Demo
public class ExampleClass {
   private String name;
   private int age;
   public ExampleClass(String name, int age){
      this.name = name;
      this.age = age;
   }
   public void display(){
      this = new ExampleClass("krishna", 23);
   }
}
On compiling, this program gives you an error as shown below −
ExampleClass.java:14: error: cannot assign a value to final variable this
      this = new ExampleClass("krishna", 23);
      ^
1 error
{{ form.as_p }} – Render Django Forms as paragraph

13 Feb, 2020
Django forms are an advanced set of HTML forms that can be created using python and support all features of HTML forms in a pythonic way. Rendering Django Forms in the template may seem messy at times but with proper knowledge of Django Forms and attributes of fields, one can easily create excellent Form with all powerful features. In this article, Form is rendered as paragraphs in the template.
Illustration of {{ form.as_p }} using an Example. Consider a project named geeksforgeeks having an app named geeks.
Refer to the following articles to check how to create a project and an app in Django.
How to Create a Basic Project using MVT in Django?
How to Create an App in Django ?
Let’s create a sample Django Form to render it and show as an example. In geeks > forms.py, enter following code
from django import forms   # creating a form class InputForm(forms.Form):       first_name = forms.CharField(max_length = 200)    last_name = forms.CharField(max_length = 200)    roll_number = forms.IntegerField(                     help_text = "Enter 6 digit roll number"                     )    password = forms.CharField(widget = forms.PasswordInput())
Now we need a View to render this form into a template. Let’s create a view,
from django.shortcuts import renderfrom .forms import InputForm   # Create your views here.def home_view(request):    context ={}    context['form']= InputForm()    return render(request, "home.html", context)
Finally, we will create the template where we need the form to be placed. In templates > home.html,
<form action = "" method = "post">    {% csrf_token %}    {{form.as_p }}    <input type="submit" value=Submit"></form>
Here {{ form.as_p }} will render them wrapped in <p> tags. Let’s check whether this is working acordingly or not. Open http://localhost:8000/
Let’s check the source code whether the form is rendered as a paragraph or not. By rendering as a paragraph it is meant that all input fields will be enclosed in <p> tags.Here is the demonstration,
{{ form.as_table }} will render them as table cells wrapped in <tr> tags
{{ form.as_ul }} will render them wrapped in <li> tags
NaveenArora
Django-forms
Python Django
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Java Program to Reverse a Number

08 Jul, 2022
Reversing a number means that the digit at the first position should be swapped with the last digit, the second digit will be swapped with the second last digit, and so on till the middle element,
To reverse a number following steps should be performed:
Take the number’s modulo by 10
Multiply the reverse number by 10 and add modulo value into the reverse number.
Divide the number by 10.
Repeat above steps until number becomes zero.
We can reverse a number in java using two methods. 
1. Using While Loop:  
 Simply apply the steps/algorithm discussed and terminate the loop when the number becomes zero. 
Take the number’s modulo by 10
Multiply the reverse number by 10 and add modulo value into the reverse number.
Divide the number by 10.
Repeat the above steps until the number becomes zero.
Below is the implementation of the above approach:
Java
// Java program to reverse a number import java.io.*; class GFG {         // Function to reverse the number    static int reverse(int n){             int rev = 0; // reversed number      int rem;   // remainder             while(n>0){                  rem = n%10;        rev = (rev*10) + rem;        n = n/10;      }             return rev;    }        // Driver Function    public static void main (String[] args) {        int n = 4526;                 System.out.print("Reversed Number is "+ reverse(n));    }}
Reversed Number is 6254
2. Using Recursion: 
In recursion, the final reverse value will be stored in the global ‘rev’ variable. Follow the below instructions.
If the number becomes zero then terminate the recursion, this will be the base condition.
Take the modulo and add it with the ‘rev*10’ multiplying.
Divide the number by 10 and call the reverse function on this number after updating it to number/10.
Below is the Java implementation of the recursion method.
Java
// Java program to reverse a number recursively import java.io.*; class GFG {          // stores reversed number    static int rev = 0;       // Function to reverse the number    static void reverse(int n){             if(n<=0)        return ;             int rem = n%10;  // remainder             rev = (rev*10) + rem;             reverse(n/10);    }        // Driver Function    public static void main (String[] args) {               int n = 4526;              reverse(n);               System.out.print("Reversed Number is "+ rev);    }}
Reversed Number is 6254
Time Complexity : O(logn) ,where n is number
Auxiliary Space: O(logn)
aditya942003patil
Picked
Java
Java Programs
Java
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Stream In Java
Introduction to Java
Constructors in Java
Exceptions in Java
Generics in Java
Java Programming Examples
Convert Double to Integer in Java
Implementing a Linked List in Java using Class
Factory method design pattern in Java
Java Program to Remove Duplicate Elements From the Array
TypeScript - String toUpperCase()

This method returns the calling string value converted to uppercase.
string.toUpperCase( )

Returns a string representing the specified object.
var str = "Apples are round, and Apples are Juicy."; 
console.log(str.toUpperCase( ));

On compiling, it will generate the same code in JavaScript.
Its output is as follows −
APPLES ARE ROUND, AND APPLES ARE JUICY.
Python | Swap commas and dots in a String

17 Feb, 2021
The problem is quite simple. Given a string, we need to replace all commas with dots and all dots with the commas. This can be achieved in two popular ways. Examples: 
Input : 14, 625, 498.002
Output : 14.625.498, 002 
Using maketrans and translate()
maketrans: This static method returns a translation table usable for str.translate(). This builds a translation table, which is a mapping of integers or characters to integers, strings, or None.translate: This returns a copy of the string where all characters occurring in the optional argument are removed, and the remaining characters have been mapped through the translation table, given by the maketrans table. For more reference visit Python String Methods.  
Python3
# Python code to replace, with . and vice-versadef Replace(str1):    maketrans = str1.maketrans    final = str1.translate(maketrans(',.', '.,', ' '))    return final.replace(',', ", ")  # Driving Codestring = "14, 625, 498.002"print(Replace(string))
Output: 
14.625.498, 002
Using replace()
This is more of a logical approach in which we swap the symbols considering third variables. The replace method can also be used to replace the methods in strings. We can convert “, ” to a symbol then convert “.” to “, ” and the symbol to “.”. For more reference visit Python String Methods. Example:  
Python3
def Replace(str1):    str1 = str1.replace(', ', 'third')    str1 = str1.replace('.', ', ')    str1 = str1.replace('third', '.')    return str1     string = "14, 625, 498.002"print(Replace(string))
Output: 
14.625.498, 002
rahulpoluri314
Python string-programs
python-string
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to Install PIP on Windows ?
Python Classes and Objects
Python OOPs Concepts
Python | os.path.join() method
How to drop one or multiple columns in Pandas Dataframe
Introduction To PYTHON
How To Convert Python Dictionary To JSON?
Check if element exists in list in Python
Python | datetime.timedelta() function
Python | Get unique values from a list
Get first n records of a Pandas DataFrame

05 Aug, 2020
Let us see how to fetch the first n records of a Pandas DataFrame. Lets first make a dataframe :
# Import Required Libraryimport pandas as pd  # Create a dictionary for the dataframedict = {'Name' : ['Sumit Tyagi', 'Sukritin',                  'Akriti Goel', 'Sanskriti',                  'Abhishek Jain'],        'Age':[22, 20, 45, 21, 22],        'Marks':[90, 84, 33, 87, 82]}  # Converting Dictionary to Pandas Dataframedf = pd.DataFrame(dict)  # Print Dataframeprint(df)
Output :  
Method 1 : Using head() method. Use pandas.DataFrame.head(n) to get the first n rows of the DataFrame. It takes one optional argument n (number of rows you want to get from the start). By default n = 5, it return first 5 rows if value of n is not passed to the method.
# Getting first 3 rows from dfdf_first_3 = df.head(3)  # Printing df_first_3print(df_first_3)
Output :  
Method 2 : Using pandas.DataFrame.iloc(). Use pandas.DataFrame.iloc() to get the first n rows. It is similar to the list slicing.
# Getting first 3 rows from dfdf_first_3 = df.iloc[:3]  # Printing df_first_3print(df_first_3)
Output :
Method 3 : Display first n records of specific columns
# Getting first 2 rows of columns Age and Marks from dfdf_first_2 = df[['Age', 'Marks']].head(2)  # Printing df_first_2print(df_first_2)
Output :  
Method 4 : Display first n records from last n columns. Display first n records for the last n columns using pandas.DataFrame.iloc()
# Getting first n rows and last n columns from dfdf_first_2_row_last_2_col = df.iloc[:2, -2:]  # Printing df_first_2_row_last_2_colprint(df_first_2_row_last_2_col)
Output :
Python pandas-dataFrame
Python Pandas-exercise
Python-pandas
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to Install PIP on Windows ?
Python Classes and Objects
Python OOPs Concepts
Introduction To PYTHON
How to drop one or multiple columns in Pandas Dataframe
Python | os.path.join() method
Check if element exists in list in Python
How To Convert Python Dictionary To JSON?
Python | Get unique values from a list
Python | datetime.timedelta() function
How to use TextareaAutosize Component in ReactJS?

02 Mar, 2021
A textarea component for React which grows with content. Material UI for React has this component available for us, and it is very easy to integrate. We can use the TextareaAutosize Component in ReactJS using the following approach.
Creating React Application And Installing Module:
Step 1: Create a React application using the following command.
npx create-react-app foldername
Step 2: After creating your project folder i.e. foldername, move to it using the following command.
cd foldername
Step 3: After creating the ReactJS application, Install the material-ui modules using the following command.
npm install @material-ui/core
Project Structure: It will look like the following.
Project Structure
Example: Now write down the following code in the App.js file. Here, App is our default component where we have written our code. 
App.js
import React from 'react';import TextareaAutosize from '@material-ui/core/TextareaAutosize';  export default function App() {    return (    <div style={{ display: 'block', padding: 30, width: 500 }}>      <h4>How to use TextareaAutosize Component in ReactJS?</h4>      <TextareaAutosize style={{width: 150}}       placeholder="Enter your text here!" />    </div>  );}
Step to Run Application: Run the application using the following command from the root directory of the project.
npm start
Output: Now open your browser and go to http://localhost:3000/, you will see the following output.
Reference: https://material-ui.com/components/textarea-autosize/
React-Questions
ReactJS
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Axios in React: A Guide for Beginners
ReactJS useNavigate() Hook
How to install bootstrap in React.js ?
How to create a multi-page website using React.js ?
How to do crud operations in ReactJS ?
How to Use Bootstrap with React?
React-Router Hooks
How to navigate on path by button click in react router ?
How to check the version of ReactJS ?
How to Create a Countdown Timer Using ReactJS ?
How to insert line break before an element using CSS?

04 Apr, 2019
The white-space property is used to insert the line break before an element. This property controls the text wrapping and white-spacing.
Line break between the lines: The line break can be added between the line of text. The white-space: preline; is used to insert line break before an element.
Example 1:
<!DOCTYPE html><html>  <head>    <title>        Insert line break        before an element    </title>          <!-- CSS style to insert line break        before an element -->    <style>        p {             color:green;            white-space: pre-line;        }    </style></head>  <body>    <h1>GeeksforGeeks</h1>          <h2>        Insert line break before an         element    </h2>          <p>        Data Structure        Algorithm        Computer Networks        Web Technology    </p></body>  </html>                    
Output:
Line-break between HTML Elements: The line-break between HTML elements can be added by using CSS properties. There are two methods to force inline elements to add new line.
Using display property: A block-level element starts on a new line, and takes up the entire width available to it.
Using carriage return character (\A): We can add a new-line by using the ::before or ::after pseudo-elements.
Example 2:
<!DOCTYPE html><html>  <head>    <title>        Insert line break and content        before an element    </title>      <!--It adds the GeeksforGeeks        A computer science portal -->    <style>        p::before {            color:green;            content: "GeeksforGeeks \A "                "A computer science portal";            display: block;            white-space: pre;        }    </style></head>  <body>    <h1>GeeksforGeeks</h1>          <h2>        Insert content and line break        before an element    </h2>          <p>Data Structure</p>    <p>Algorithm</p></body>  </html>                    
Output:
Example 3: This example uses carriage return character “\A” to add line break before an element.
<!DOCTYPE html><html>  <head>    <title>        Insert line break        before an element    </title>      <!-- Style to add the line break -->    <style>        p::before {            content: "\A";            white-space: pre;        }    </style></head>  <body>    <h1>GeeksforGeeks</h1>          <h2>        Insert line break        before an element    </h2>          <p>Data Structure</p>    <p>Algorithm</p>    <p>Operating System</p></body>  </html>                    
Output:
Picked
Web Technologies
Web technologies Questions
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Iterate through a LinkedList using an Iterator in Java

An Iterator can be used to loop through an LinkedList. The method hasNext( ) returns true if there are more elements in LinkedList and false otherwise. The method next( ) returns the next element in the LinkedList and throws the exception NoSuchElementException if there is no next element.
A program that demonstrates this is given as follows.
 Live Demo
import java.util.LinkedList;
import java.util.Iterator;
public class Demo {
   public static void main(String[] args) {
      LinkedList<String> l = new LinkedList<String>();
      l.add("John");
      l.add("Sara");
      l.add("Susan");
      l.add("Betty");
      l.add("Nathan");
      System.out.println("The LinkedList elements are: ");
      for (Iterator i = l.iterator(); i.hasNext();) {
         System.out.println(i.next());
      }
   }
}
The output of the above program is as follows −
The LinkedList elements are:
John
Sara
Susan
Betty
Nathan
Now let us understand the above program.
The LinkedList is created and LinkedList.add() is used to add the elements to the LinkedList. Then the LinkedList elements are displayed using an iterator which makes use of the Iterator interface. A code snippet which demonstrates this is as follows
LinkedList<String> l = new LinkedList<String>();
l.add("John");
l.add("Sara");
l.add("Susan");
l.add("Betty");
l.add("Nathan");
System.out.println("The LinkedList elements are: ");
for (Iterator i = l.iterator(); i.hasNext();) {
   System.out.println(i.next());
}
DAX Text - CONCATENATEX function

Concatenates the result of an expression evaluated for each row in a table.
DAX CONCATENATEX function is new in Excel 2016.
CONCATENATEX (
   <table>, <expression>, [<delimiter>], [<OrderBy_Expression1>], [<Order>] ...
) 

table
The table containing the rows for which the expression will be evaluated.
expression
The expression to be evaluated for each row of the table.
delimiter
Optional.
A separator to use during concatenation.
OrderBy_Expression1
Optional.
Column by which the values are to be concatenated.
Order
Optional.
ASC: To sort in an ascending order.
DESC: To sort in a descending order.
If omitted, default is ASC.
A single text string.
CONCATENATEX function takes as its first parameter, a table or an expression that returns a table.
The second parameter is a column that contains the values you want to concatenate, or an expression that returns a value.
CONCATENATEX (Products, [Product],", ", [Product Key], ASC)
   returns Air Purifier, Detergent Powder, Floor Cleaner, Hand Wash, Soap.
   
= CONCATENATEX (Products, [Product],",", [Product Key], DESC) 
   returns Soap, Hand Wash, Floor Cleaner, Detergent Powder, Air Purifier. 

= CONCATENATEX (Products, [Product],", ", [Product Key]) 
   returns Air Purifier, Detergent Powder, Floor Cleaner, Hand Wash, Soap.

    53 Lectures 
     5.5 hours 

 Abhay Gadiya

    24 Lectures 
     2 hours 

 Randy Minder

    26 Lectures 
     4.5 hours 

 Randy Minder
 Print
 Add Notes
 Bookmark this page
Merge Sort Program in C

Merge sort is a sorting technique based on divide and conquer technique. With the worst-case time complexity being Ο(n log n), it is one of the most respected algorithms.
We shall see the implementation of merge sort in C programming language here −
#include <stdio.h>

#define max 10

int a[11] = { 10, 14, 19, 26, 27, 31, 33, 35, 42, 44, 0 };
int b[10];

void merging(int low, int mid, int high) {
   int l1, l2, i;

   for(l1 = low, l2 = mid + 1, i = low; l1 <= mid && l2 <= high; i++) {
      if(a[l1] <= a[l2])
         b[i] = a[l1++];
      else
         b[i] = a[l2++];
   }
   
   while(l1 <= mid)    
      b[i++] = a[l1++];

   while(l2 <= high)   
      b[i++] = a[l2++];

   for(i = low; i <= high; i++)
      a[i] = b[i];
}

void sort(int low, int high) {
   int mid;
   
   if(low < high) {
      mid = (low + high) / 2;
      sort(low, mid);
      sort(mid+1, high);
      merging(low, mid, high);
   } else { 
      return;
   }   
}

int main() { 
   int i;

   printf("List before sorting\n");
   
   for(i = 0; i <= max; i++)
      printf("%d ", a[i]);

   sort(0, max);

   printf("\nList after sorting\n");
   
   for(i = 0; i <= max; i++)
      printf("%d ", a[i]);
}
If we compile and run the above program, it will produce the following result −
List before sorting
10 14 19 26 27 31 33 35 42 44 0
List after sorting
0 10 14 19 26 27 31 33 35 42 44


    42 Lectures 
     1.5 hours 

 Ravi Kiran

    141 Lectures 
     13 hours 

 Arnab Chakraborty

    26 Lectures 
     8.5 hours 

 Parth Panjabi

    65 Lectures 
     6 hours 

 Arnab Chakraborty

    75 Lectures 
     13 hours 

 Eduonix Learning Solutions

    64 Lectures 
     10.5 hours 

 Eduonix Learning Solutions
 Print
 Add Notes
 Bookmark this page
Tryit Editor v3.7

Tryit: HTML paragraph with br
Complex numbers in C++

In this section we will see how to create and use complex numbers in C++. We can
create complex number class in C++, that can hold the real and imaginary part of the
complex number as member elements. There will be some member functions that
are used to handle this class.
In this example we are creating one complex type class, a function to display
the complex number into correct format. Two additional methods to add and
subtract two complex numbers etc.
 Live Demo
#include<iostream>
using namespace std;
class complex {
   int real, img;
   public:
      complex() {
         //default constructor to initialize complex number to 0+0i
         real = 0; img = 0;
      }
      complex(int r, int i) {
         //parameterized constructor to initialize complex number.
         real = r; img = i;
      }
      void set();
      void get();
      void display();
      friend complex add(complex, complex);
      friend complex sub(complex, complex);
};
void complex::set() {
   cout << "Enter Real part: ";
   cin >> real;
   cout << "Enter Imaginary Part: ";
   cin >> img;
}
void complex::get() {
   cout << "The complex number is: "<< real << "+" << img << "i" << endl;
}
void complex::display() {
   if(img < 0)
      if(img == -1)
         cout << "The complex number is: "<< real << "-i" << endl;
      else
         cout << "The complex number is: "<< real << img << "i" << endl;
      else
         if(img == 1)
            cout << "The complex number is: "<< real << " + i"<< endl;
         else
            cout << "The complex number is: "<< real << " + " << img << "i" <<
   endl;
}
complex add(complex c1, complex c2) {
   complex res;
   res.real = c1.real + c2.real;//addition for real part
   res.img = c1.img + c2.img;//addition for imaginary part
   return res;//the result after addition
}
complex sub(complex c1, complex c2) {
   complex res;
   res.real = c1.real - c2.real;//subtraction for real part
   res.img = c1.img - c2.img;//subtraction for imaginary part
   return res;//the result after subtraction
}
main() {
   complex n1(3, 2), n2(4, -3);
   complex result;
   result = add(n1,n2);
   result.display();
   result = sub(n1,n2);
   result.display();
}
The complex number is: 7-i
The complex number is: -1 + 5i