code-rag-bench/online-tutorials huggingface dataset:
Java Substring | Practice | GeeksforGeeks

Given a string S and two integers L and R. Print the characters in the range L to R of the string.
NOTE: Assume zero based indexing.

Example 1:
Input: 
S = "cdbkdub"
L = 0 , R = 5
Output: "cdbkdu" 
Explanation: Starting from index 0 ('c')
to index 5 ('u').

Example 2:
Input: 
S = "sdiblcsdbud"
L = 3 , R = 7
Output: "blcsd"
Explanation: Starting from index 3 ('b')
to index 7 ('d').

Your Task:  
You dont need to read input or print anything. Complete the function javaSub() which takes S, L, R as input parameter and returns the sting from the range L to R.

Expected Time Complexity: O(|S|)
Expected Auxiliary Space: O(|S|)

Constraints:
1<= |S| <=1000
1 <= L <= 800
1 <= R <= 900
0
neelasatyasai931 month ago
#PYTHON
class Solution:   def javaSub (ob, S, L, R):       return S[L:R+1]
+1
kumarsunnysuman20023 months ago
JAVA CODE :-
class Solution {   static String javaSub(String S, int L, int R) {       String str = "";       for(int i = L; i <= R; i++)           str += S.charAt(i);       return str;   }}
0
vishwajeetofficial20223 months ago
// JAVA SOLUTION

class Solution {
    static String javaSub(String S, int L, int R) {
        // code here
        String res="";
        for(int i=L; i<=R; i++){
            res+=S.charAt(i);
        }
        return res.toString();
    }
}
0
ayazmrz983 months ago
 string javaSub(string S, int L, int R) {
       string result="";
       for(int i=L;i<=R;i++)
       {
           result +=S[i];
       }
       return result;
   }
0
ayazmrz983 months ago
static String javaSub(String S, int L, int R) {
       String result="";
       for(int i=L;i<=R;i++)
       {
           result +=S.charAt(i);
       }
       return result;
   }
0
ayazmrz983 months ago
 def javaSub (ob, S, L, R):
       return S[L:R+1]
0
as0042303 months ago
In C++;
string javaSub(string S, int L, int R) {       return S.substr(L, R-L+1);   }
0
mda976714 months ago
class Solution {   static String javaSub(String S, int L, int R) {       // code here       return S.substring(L,R+1);   }}
-1
rrishav3187 months ago
 String s="";    for(int i=L; i<=R; i++){       s=s+S.charAt(i);    }              return s; 
0
Kartik Verma10 months ago
Kartik Verma
public class main{    public static void main(String args[])    {      String S = "cdbkdub";      String s1 = S.substring(0,6);      System.out.println(s1);    }}
We strongly recommend solving this problem on your own before viewing its editorial. Do you still
                    want to view the editorial?
 Login to access your submissions. 

Problem


Contest

Reset the IDE using the second button on the top right corner.
Avoid using static/global variables in your code as your code is tested against multiple test cases and these tend to retain their previous values.
Passing the Sample/Custom Test cases does not guarantee the correctness of code. On submission, your code is tested against multiple test cases consisting of all possible corner cases and stress constraints.
You can access the hints to get an idea about what is expected of you as well as the final solution code.
You can view the solutions submitted by other users from the submission tab.
Python - Ways to rotate a list

List is an important container and used almost in every code of day-day programming as well as web-development, more it is used, more is the requirement to master it and hence knowledge of its operations is necessary.
 Live Demo
# using slice
# initializing list
test_list = [1, 4, 6, 7, 2]  
# printing original list
print ("Original list : " + str(test_list))  
# using slicing to left rotate by 3
test_list = test_list[3:] + test_list[:3]  
# Printing list after left rotate
print ("List after left rotate by 3 : " + str(test_list))  
# using slicing to right rotate by 3
# back to Original
test_list = test_list[-3:] + test_list[:-3]
# Printing after right rotate
print ("List after right rotate by 3(back to original) : " + str(test_list))
# using list comprehension  
# initializing list
test_list = [1, 4, 6, 7, 2]  
# printing original list
print ("Original list : " + str(test_list))  
# using list comprehension to left rotate by 3
test_list = [test_list[(i + 3) % len(test_list)]
   for i, x in enumerate(test_list)]  
# Printing list after left rotate
print ("List after left rotate by 3 : " + str(test_list))
# using list comprehension to right rotate by 3
# back to Original
test_list = [test_list[(i - 3) % len(test_list)]
   for i, x in enumerate(test_list)]
# Printing after right rotate
print ("List after right rotate by 3(back to original) : " + str(test_list))
# using rotate()
from collections import deque  
# initializing list
test_list = [1, 4, 6, 7, 2]  
# printing original list
print ("Original list : " + str(test_list))  
# using rotate() to left rotate by 3
test_list = deque(test_list)
test_list.rotate(-3)
test_list = list(test_list)  
# Printing list after left rotate
print ("List after left rotate by 3 : " + str(test_list))  
# using rotate() to right rotate by 3
# back to Original
test_list = deque(test_list)
test_list.rotate(3)
test_list = list(test_list)  
# Printing after right rotate
print ("List after right rotate by 3(back to original) : " + str(test_list))
Original list : [1, 4, 6, 7, 2]
List after left rotate by 3 : [7, 2, 1, 4, 6]
List after right rotate by 3(back to original) : [1, 4, 6, 7, 2]
Original list : [1, 4, 6, 7, 2]
List after left rotate by 3 : [7, 2, 1, 4, 6]
List after right rotate by 3(back to original) : [1, 4, 6, 7, 2]
Original list : [1, 4, 6, 7, 2]
List after left rotate by 3 : [7, 2, 1, 4, 6]
List after right rotate by 3(back to original) : [1, 4, 6, 7, 2]
How to use a variable in a string in jQuery?

jQuery is a JavaScript library introduced to make development with JavaScript easier. Let us see how to use variable in a string using the html() method.
You can try to run the following code to learn how to use variable in a string in jQuery −
Live Demo
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
   $(function(){
      $("a").click(function(){
        var id= $(".id").html();
        $('.myclass').html("<br><div class='new' id='" + id + "'>Hello</div>");            
      });
   });
</script>
</head>
<body>
   <div class="wrap">
      <a href="#">Click me</a>
      <div class="myclass"></div>
      <div class="id">Learners</div>
   </div>
</body>
</html>
How to perform heapsort on an array in Java?

Following is the algorithm for heapsort (maxheap).
Step 1 − Create a new node at the end of the heap.
Step 2 − Assign new value to the node.
Step 3 − Compare the value of this child node with its parent.
Step 4 − If the value of parent is less than a child, then swap them.
Step 5 − Repeat step 3 & 4 until Heap property holds.
import java.util.Arrays;
import java.util.Scanner;

public class Heapsort {
   public static void heapSort(int[] myArray, int length) {
      int temp;
      int size = length-1;
      for (int i = (length / 2); i >= 0; i--) {
         heapify(myArray, i, size);
      };
      for(int i= size; i>=0; i--) {
         temp = myArray[0];
         myArray[0] = myArray[size];
         myArray[size] = temp;
         size--;
         heapify(myArray, 0, size);
      }
      System.out.println(Arrays.toString(myArray));
   }
   public static void heapify (int [] myArray, int i, int heapSize) {
      int a = 2*i;
      int b = 2*i+1;
      int largestElement;
      if (a<= heapSize && myArray[a] > myArray[i]) {
         largestElement = a;
      } else {
         largestElement = i;
      }
      if (b <= heapSize && myArray[b] > myArray[largestElement]) {
         largestElement = b;
      }
      if (largestElement != i) {
         int temp = myArray[i];
         myArray[i] = myArray[largestElement];
         myArray[largestElement] = temp;
         heapify(myArray, largestElement, heapSize);
     }
   }
   public static void main(String args[]) {
      Scanner scanner = new Scanner(System.in);
      System.out.println("Enter the size of the array :: ");
      int size = scanner.nextInt();
      System.out.println("Enter the elements of the array :: ");
      int[] myArray = new int[size];
      for(int i=0; i<size; i++) {
         myArray[i] = scanner.nextInt();
      }
      heapSort(myArray, size);
   }
}
Enter the size of the array ::
5
Enter the elements of the array ::
45
125
44
78
1
[1, 44, 45, 78, 125]
GATE | GATE CS 2011 | Question 28 - GeeksforGeeks

19 Nov, 2018
On a non-pipelined sequential processor, a program segment, which is a part of the interrupt service routine, is given to transfer 500 bytes from an I/O device to memory.

              Initialize the address register
              Initialize the count to 500
        LOOP: Load a byte from device
              Store in memory at address given by address register
              Increment the address register
              Decrement the count
              If count != 0 go to LOOP 
Assume that each statement in this program is equivalent to machine instruction which takes one clock cycle to execute if it is a non-load/store instruction. The load-store instructions take two clock cycles to execute.
The designer of the system also has an alternate approach of using DMA controller to implement the same transfer. The DMA controller requires 20 clock cycles for initialization and other overheads. Each DMA transfer cycle takes two clock cycles to transfer one byte of data from the device to the memory.What is the approximate speedup when the DMA controller based design is used in place of the interrupt driven program based input-output?(A) 3.4(B) 4.4(C) 5.1(D) 6.7Answer: (A)Explanation:
 Explanation:
                        STATEMENT                                           CLOCK CYCLE(S) NEEDED
              Initialize the address register                                        1
              Initialize the count to 500                                            1
        LOOP: Load a byte from device                                                2
              Store in memory at address given by address register                   2
              Increment the address register                                         1
              Decrement the count                                                    1
              If count != 0 go to LOOP                                               1

        Interrrupt driven transfer time = 1+1+500×(2+2+1+1+1) = 3502
        DMA based transfer time = 20+500*2 = 1020
        Speedup = 3502/1020 ≈ 3.4

Source: http://clweb.csa.iisc.ernet.in/rahulsharma/gate2011key.html
Quiz of this Question
GATE-CS-2011
GATE-GATE CS 2011
GATE
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
GATE | GATE-IT-2004 | Question 66
GATE | GATE-CS-2014-(Set-3) | Question 65
GATE | GATE-CS-2006 | Question 49
GATE | GATE-CS-2004 | Question 3
GATE | GATE CS 2011 | Question 65
GATE | GATE CS 2019 | Question 27
GATE | GATE CS 2021 | Set 1 | Question 47
GATE | GATE CS 2011 | Question 7
GATE | GATE-CS-2017 (Set 2) | Question 42
GATE | GATE-IT-2004 | Question 71
How to set a property value by reflection in C#?

The System. Reflection namespace contains classes that allow you to obtain information about the application and to dynamically add types, values, and objects to the application.
Reflection objects are used for obtaining type information at runtime. The classes that give access to the metadata of a running program are in the System. Reflection namespace.
Reflection allows view attribute information at runtime.
Reflection allows examining various types in an assembly and instantiate these types.
Reflection allows late binding to methods and properties.
Reflection allows creating new types at runtime and then performs some tasks using those types.
Searches for the public property with the specified name.
Gets the Type object with the specified name in the assembly instance and optionally throws an exception if the type is not found.
Sets the property value of a specified object.
class Program{
   static void Main(string[] args){
      User user = new User();
      Type type = user.GetType();
      PropertyInfo prop = type.GetProperty("Name");
      prop.SetValue(user, "Bangalore", null);
      System.Console.WriteLine(user.Name);
      Console.ReadLine();
   }
}
class User{
   public int Id { get; set; }
   public string Name { get; set; }
}
Bangalore
JavaScript Array isArray() Method - GeeksforGeeks

01 Nov, 2021
Below is the example of the Array isArray() method.
Example:<script>    // JavaScript code for isArray() function    function func() {        document.write(Array.isArray('foobar'));    }     func();</script>
<script>    // JavaScript code for isArray() function    function func() {        document.write(Array.isArray('foobar'));    }     func();</script>
Output:false
false
The arr.isArray() method determines whether the value passed to this function is an array or not. This function returns true if the argument passed is array else it returns false.
Syntax:
Array.isArray(obj)
Parameters: This method accept a single parameter as mentioned above and described below:
obj: This parameter holds the object that will be tested.
Return value: This function returns the Boolean value true if the argument passed is array otherwise it returns false.
Below example illustrate the Array isArray() method in JavaScript:
Example 1: Since the argument passed to the function isArray() is an array therefore this function returns true as the answer.Input : print(Array.isArray(['Day','Night','Evening']));
Output: true

Input : print(Array.isArray(['Day','Night','Evening']));
Output: true

Example 2: Since the argument passed to the function isArray() is a map therefore this function returns false as the answer.Input : print(Array.isArray({foo: 123}));
Output: false

Input : print(Array.isArray({foo: 123}));
Output: false

Example 3: Since the argument passed to the function isArray() is a string therefore this function returns false as the answer.Input : print(Array.isArray('foobar'));
Output: false

Input : print(Array.isArray('foobar'));
Output: false

Code for the above method is provided below:
Program 1:
<script>    // JavaScript code for isArray() function    function func() {        document.write(Array.isArray(['Day','Night','Evening']));    }    func();</script>
Output:
true
Program 2:
<script>    // JavaScript code for isArray() function    function func() {        document.write(Array.isArray({foo: 123}));    }    func();</script>
Output:
false
Supported Browsers: The browsers supported by JavaScript Array isArray() method are listed below:
Google Chrome 5.0
Microsoft Edge 12
Mozilla Firefox 4.0
Safari 5.0
Opera 10.5
ysachin2314
javascript-array
JavaScript-Methods
JavaScript
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Remove elements from a JavaScript Array
Convert a string to an integer in JavaScript
Difference between var, let and const keywords in JavaScript
Differences between Functional Components and Class Components in React
Difference Between PUT and PATCH Request
Remove elements from a JavaScript Array
Installation of Node.js on Linux
Convert a string to an integer in JavaScript
How to fetch data from an API in ReactJS ?
How to insert spaces/tabs in text using HTML/CSS?
How to check whether a String contains a substring or not?

This example shows how we can search a word within a String object using indexOf() method which returns a position index of a word within the string if found. Otherwise, it returns -1. 
public class SearchStringEmp {
   public static void main(String[] args) {
      String strOrig = "Hello readers"; int intIndex = strOrig.indexOf("Hello"); if(intIndex == - 1) {
         System.out.println("Hello not found");
      } else {
         System.out.println("Found Hello at index " + intIndex);
      }
   }
}
The above code sample will produce the following result. 
Found Hello at index 0
How to find the Strings within a text file in Java?

Following Java program accepts a String value from the user, verifies whether a file contains the given String and prints the number of occurrences of the word too.
 Live Demo
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class FindingWordFromFile {
   public static void main(String args[]) throws FileNotFoundException {
      //Reading the word to be found from the user
      Scanner sc1 = new Scanner(System.in);
      System.out.println("Enter the word to be found");
      String word = sc1.next();
      boolean flag = false;
      int count = 0;
      System.out.println("Contents of the line");
      //Reading the contents of the file
      Scanner sc2 = new Scanner(new FileInputStream("D:\\sampleData.txt"));
      while(sc2.hasNextLine()) {
         String line = sc2.nextLine();
         System.out.println(line);
         if(line.indexOf(word)!=-1) {
            flag = true;
            count = count+1;
         }
      }
      if(flag) {
         System.out.println("File contains the specified word");
         System.out.println("Number of occurrences is: "+count);
      } else {
         System.out.println("File does not contain the specified word");
      }
   }
}
Enter the word to be found
the
Contents of the line
Tutorials Point originated from the idea that there exists a class of readers who respond better 
to online content and prefer to learn new skills at their own pace from the comforts of their drawing rooms.
The journey commenced with a single tutorial on HTML in 2006 and elated by the response it generated, 
we worked our way to adding fresh tutorials to our repository which now proudly flaunts a wealth of 
tutorials and allied articles on topics ranging from programming languages to web designing to academics and much more.
40 million readers read 100 million pages every month
Our content and resources are freely available and we prefer to keep it that way to encourage our readers
 acquire as many skills as they would like to. We don’t force our readers to sign up with us or submit 
their details either. No preconditions and no impediments. Simply Easy Learning!
File contains the specified word
Number of occurrences is: 3
Java Method Overloading

With method overloading, multiple methods can have the same name with different
parameters:
int myMethod(int x)
float myMethod(float x)
double myMethod(double x, double y)
Consider the following example, which has two methods that add numbers of different type:
static int plusMethodInt(int x, int y) {
  return x + y;
}

static double plusMethodDouble(double x, double y) {
  return x + y;
}

public static void main(String[] args) {
  int myNum1 = plusMethodInt(8, 5);
  double myNum2 = plusMethodDouble(4.3, 6.26);
  System.out.println("int: " + myNum1);
  System.out.println("double: " + myNum2);
}

Try it Yourself »

Instead of defining two methods that should do the same thing, it is better to overload one. 
In the example below, we overload the plusMethod 
method to work for both int 
and double:
static int plusMethod(int x, int y) {
  return x + y;
}

static double plusMethod(double x, double y) {
  return x + y;
}

public static void main(String[] args) {
  int myNum1 = plusMethod(8, 5);
  double myNum2 = plusMethod(4.3, 6.26);
  System.out.println("int: " + myNum1);
  System.out.println("double: " + myNum2);
} 
 
 
 


Try it Yourself »

Note: Multiple methods can have the same name 
  as long as the number and/or type of parameters are different.
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.
ASP AddHeader Method - GeeksforGeeks

04 Aug, 2020
The ASP AddHeader Method is used to specify for adding a new named for the HTTP Header and provide and given a value to the HTTP Response. It is a method of a Response type Object. 
Once a header has been added then it can not be further removed.
This method must be called before any output is sent to the client unless the Response. Buffer is set to true.
Syntax:
response.AddHeader name,value

 Parameter Values: This method accepts two parameters as mentioned above and described below:
name: It defines the name of the new header variable. The name cannot contain any underscores (_).
value: It defines the initial value of the new header variable.
 Return Values: This method has not returned any value. 
 Example 1:
<% Response.AddHeader "WARNING","Error message text %>

   
Example 2: Below code uses the AddHeader method to request that the client use Basic authentication.
<% Response.Addheader "WWW-Authenticate", "BASIC" %>

Example 3:  
<% Response.AddHeader "CustomHeader", "CustomValue" %>
Reference: https://docs.microsoft.com/en-us/previous-versions/iis/6.0-sdk/ms524327(v=vs.90)
ASP-Properties
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Top 10 Front End Developer Skills That You Need in 2022
How to fetch data from an API in ReactJS ?
Difference between var, let and const keywords in JavaScript
Convert a string to an integer in JavaScript
Differences between Functional Components and Class Components in React
How to set the default value for an HTML <select> element ?
How to create footer to stay at the bottom of a Web page?
Node.js fs.readFileSync() Method
File uploading in React.js
How to Open URL in New Tab using JavaScript ?
Berkeley’s Algorithm in C/C++

Berkeley’s Algorithm is an algorithm that is used for clock Synchronisation in distributed systems. This algorithm is used in cases when some or all systems of the distributed network have one of these issues −
A. The machine does not have an accurate time source.
A. The machine does not have an accurate time source.
B. The network or machine does not have a UTC server.
B. The network or machine does not have a UTC server.
Distributed system contains multiple nodes that are physically separated but are linked together using a network.
In this algorithm, the system chooses a node as master/ leader node. This is done from pool nodes in the server.
The algorithm is −
An election process chooses the master node in the server.
An election process chooses the master node in the server.
The leader then polls followers that provide their time in a way similar to Cristian’s Algorithm, this is done periodically.
The leader then polls followers that provide their time in a way similar to Cristian’s Algorithm, this is done periodically.
The leader then calculates the relative time that other nodes have to change or adjust to synchronize to the global clock time which is the average of times that are provided to the leader node.
The leader then calculates the relative time that other nodes have to change or adjust to synchronize to the global clock time which is the average of times that are provided to the leader node.
Let’s sum-up steps followed to synchronize the clock using the Berkeley algorithm,
Nodes in the distributed system with their clock timings −
N1 -> 14:00 (master node)
N2 -> 13: 46
N3 -> 14: 15
Step 1 − The Leader is elected, node N1 is the master in the system.
Step 2 − leader requests for time from all nodes.
N1 -> time : 14:00
N2 -> time : 13:46
N3 -> time : 14:20
Step 3 − The leader averages the times and sends the correction time back to the nodes.
N1 -> Corrected Time 14:02 (+2)
N2 -> Corrected Time 14:02 (+16)
N3 -> Corrected Time 14:02 (-18)
This shows how the synchronization of nodes of a distributed system is done using Berkeley’s algorithm.
Java program to find the area of a rectangle

Area of a rectangle is the product of its length and breadth. Therefore, to calculate the area of a rectangle
Get the length of the rectangle form the user.
Get the breadth of the rectangle form the user.
Calculate their product.
Print the product.
import java.util.Scanner;
public class AreaOfRectangle {
   public static void main(String args[]){
      int length, breadth, area;
      Scanner sc = new Scanner(System.in);
      System.out.println("Enter the length of the rectangle ::");
      length = sc.nextInt();
      System.out.println("Enter the breadth of the rectangle ::");
      breadth = sc.nextInt();
      area = length* breadth;
      System.out.println("Area of the rectangle is ::"+area);
   }
}
Enter the length of the rectangle ::
56
Enter the breadth of the rectangle ::
48
Area of the rectangle is ::2688
Shell Scripting Tutorial

A shell script is a computer program designed to be run by the Unix/Linux shell which could be one of the following:
The Bourne Shell
The C Shell
The Korn Shell
The GNU Bourne-Again Shell
 A shell is a command-line interpreter and typical operations performed by shell scripts include file manipulation, program execution, and printing text.
Shell scripts have several required constructs that tell the shell environment what to do and when to do it. Of course, most scripts are more complex than the above one.
The shell is, after all, a real programming language, complete with variables, control structures, and so forth. No matter how complicated a script gets, it is still just a list of commands executed sequentially.
The following script uses the read command which takes the input from the keyboard and assigns it as the value of the variable PERSON and finally prints it on STDOUT.
#!/bin/sh

# Author : Zara Ali
# Copyright (c) Tutorialspoint.com
# Script follows here:

echo "What is your name?"
read PERSON
echo "Hello, $PERSON"
Here is a sample run of the script −
$./test.sh
What is your name?
Zara Ali
Hello, Zara Ali
$

Subsequent part of this tutorial will cover Unix/Linux Shell Scripting in detail.

    129 Lectures 
     23 hours 

 Eduonix Learning Solutions

    5 Lectures 
     4.5 hours 

 Frahaan Hussain

    35 Lectures 
     2 hours 

 Pradeep D

    41 Lectures 
     2.5 hours 

 Musab Zayadneh

    46 Lectures 
     4 hours 

 GUHARAJANM

    6 Lectures 
     4 hours 

 Uplatz
 Print
 Add Notes
 Bookmark this page
How to check if a given number is a Fibonacci number in Python Program ?

In this article, we will learn about the solution to the problem statement given below −
Given a number n, check whether n is a Fibonacci number or not
We all are aware that the nth Fibonacci number is the sum of the previous two Fibonacci numbers. But they also offer an interesting relation other than the recurrence relation.
A number is Fibonacci in nature if and only if (5*n2 + 4) or (5*n2 – 4) is a perfect square.
We will use this property to check whether a number is Fibonacci or not.
Now let’s see the implementation of the Python script −
 Live Demo
import math
# if x is perfect square
def isPerfectSquare(x):
   s = int(math.sqrt(x))
   return s*s == x
# if n is a Fibinacci Number
def isFibonacci(n):
   #if one of 5*n*n + 4 or 5*n*n - 4 or both is a perferct square
   return isPerfectSquare(5*n*n + 4) or isPerfectSquare(5*n*n - 4)
for i in range(1,11):
   if (isFibonacci(i) == True):
      print (i,"is a Fibonacci Number")
   else:
      print (i,"is a not Fibonacci Number")
1 is a Fibonacci Number
2 is a Fibonacci Number
3 is a Fibonacci Number
4 is a not Fibonacci Number
5 is a Fibonacci Number
6 is a not Fibonacci Number
7 is a not Fibonacci Number
8 is a Fibonacci Number
9 is a not Fibonacci Number
10 is a not Fibonacci Number
All functions and variables are declared in the global frame as shown in the image below −
In this article, we learned the solution of identifying that the given number is Fibonacci or not.
PL/SQL - DBMS Output

In this chapter, we will discuss the DBMS Output in PL/SQL. The DBMS_OUTPUT is a built-in package that enables you to display output, debugging information, and send messages from PL/SQL blocks, subprograms, packages, and triggers. We have already used this package throughout our tutorial.
Let us look at a small code snippet that will display all the user tables in the database. Try it in your database to list down all the table names −
BEGIN 
   dbms_output.put_line  (user || ' Tables in the database:'); 
   FOR t IN (SELECT table_name FROM user_tables) 
   LOOP 
      dbms_output.put_line(t.table_name); 
   END LOOP; 
END; 
/ 
The DBMS_OUTPUT package has the following subprograms −
DBMS_OUTPUT.DISABLE;
Disables message output.
DBMS_OUTPUT.ENABLE(buffer_size IN INTEGER DEFAULT 20000);
Enables message output. A NULL value of buffer_size represents unlimited buffer size.
DBMS_OUTPUT.GET_LINE (line OUT VARCHAR2, status OUT INTEGER);
Retrieves a single line of buffered information.
DBMS_OUTPUT.GET_LINES (lines OUT CHARARR, numlines IN OUT INTEGER);
Retrieves an array of lines from the buffer.
DBMS_OUTPUT.NEW_LINE;
Puts an end-of-line marker.
DBMS_OUTPUT.PUT(item IN VARCHAR2);
Places a partial line in the buffer.
DBMS_OUTPUT.PUT_LINE(item IN VARCHAR2);
Places a line in the buffer.
DECLARE 
   lines dbms_output.chararr; 
   num_lines number; 
BEGIN 
   -- enable the buffer with default size 20000 
   dbms_output.enable; 
   
   dbms_output.put_line('Hello Reader!'); 
   dbms_output.put_line('Hope you have enjoyed the tutorials!'); 
   dbms_output.put_line('Have a great time exploring pl/sql!'); 
  
   num_lines := 3; 
  
   dbms_output.get_lines(lines, num_lines); 
  
   FOR i IN 1..num_lines LOOP 
      dbms_output.put_line(lines(i)); 
   END LOOP; 
END; 
/  
When the above code is executed at the SQL prompt, it produces the following result −
Hello Reader! 
Hope you have enjoyed the tutorials! 
Have a great time exploring pl/sql!  

PL/SQL procedure successfully completed.

 Print
 Add Notes
 Bookmark this page
Regular Expression "\D" Metacharacter in Java

The subexpression/metacharacter “\D” matches the non-digits.
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegexExample {
   public static void main( String args[] ) {
      String regex = "\\D";
      String input = "This is sample text 12 24 56 89 24";
      Pattern p = Pattern.compile(regex);
      Matcher m = p.matcher(input);
      int count = 0;
      while(m.find()) {
         count++;
      }
      System.out.println("Number of matches: "+count);
   }
}
Number of matches: 24
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegexExample {
   public static void main( String args[] ) {
      String regex = "\\D";
      Scanner sc = new Scanner(System.in);
      System.out.println("Enter 5 input strings: ");
      String input[] = new String[5];
      for (int i=0; i<5; i++) {
         input[i] = sc.nextLine();
      }
      //Creating a Pattern object
      Pattern p = Pattern.compile(regex);
      System.out.println("Number of non-digit characters in each string: ");
      for(int i=0; i<5;i++) {
         //Creating a Matcher object
         Matcher m = p.matcher(input[i]);
         int count = 0;
         while(m.find()) {
            count++;
         }
         System.out.println("String "+i+": "+count);
      }
   }
}
Enter 5 input strings:
sample 1
12 35 36 63
test 243 663
hello
hello how are you *
Number of non-digit characters in each string:
String 0: 7
String 1: 3
String 2: 6
String 3: 5
String 4: 19
Python - All Possible unique K size combinations till N - GeeksforGeeks

08 Jun, 2020
Sometimes, while working with Python domain, we can have a problem in which we need to produce various combination of elements. This can be K sized unique combinations till N. This problem can have application in data domains and school programming. Let’s discuss certain ways in which this task can be performed.
Input : N = 2, K = 3Output : [(0, 0, 0), (0, 0, 1), (0, 1, 1), (1, 1, 1)]
Input : N = 4, K = 2Output : [(0, 0), (0, 1), (0, 2), (0, 3), (1, 1), (1, 2), (1, 3), (2, 2), (2, 3), (3, 3)]
Method #1 : Using product() + setdefault() + loopThe combination of above functions offers an approach to this problem. In this, we use product to perform all combinations and eliminate duplicates using setdefault() and loop by brute force approach.
# Python3 code to demonstrate working of # All Possible unique K size combinations till N# Using product() + setdefault() + loopfrom itertools import product  # initializing NN = 4  # Initialize KK = 3  # All Possible unique K size combinations till N# Using product() + setdefault() + looptemp = list(product(range(N), repeat = K))res = {}for tup in temp:    key = tuple(sorted(tup))    res.setdefault(key, []).append(tup)res = list(res.keys())  # printing result print("The unique combinations : " + str(res)) 
The unique combinations : [(0, 0, 0), (0, 0, 1), (0, 0, 2), (0, 0, 3), (0, 1, 1), (0, 1, 2), (0, 1, 3), (0, 2, 2), (0, 2, 3), (0, 3, 3), (1, 1, 1), (1, 1, 2), (1, 1, 3), (1, 2, 2), (1, 2, 3), (1, 3, 3), (2, 2, 2), (2, 2, 3), (2, 3, 3), (3, 3, 3)]
 
Method #2 : Using combinations_with_replacement()This offers an alternative method to solve this problem. This function performs internally, all that is required to get to solution.
# Python3 code to demonstrate working of # All Possible unique K size combinations till N# Using combinations_with_replacement()from itertools import product, combinations_with_replacement  # initializing NN = 4  # Initialize KK = 3  # All Possible unique K size combinations till N# Using combinations_with_replacement()res = list(combinations_with_replacement(range(N), K))  # printing result print("The unique combinations : " + str(res)) 
The unique combinations : [(0, 0, 0), (0, 0, 1), (0, 0, 2), (0, 0, 3), (0, 1, 1), (0, 1, 2), (0, 1, 3), (0, 2, 2), (0, 2, 3), (0, 3, 3), (1, 1, 1), (1, 1, 2), (1, 1, 3), (1, 2, 2), (1, 2, 3), (1, 3, 3), (2, 2, 2), (2, 2, 3), (2, 3, 3), (3, 3, 3)]
Python tuple-programs
Python
Python Programs
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Python Dictionary
Enumerate() in Python
Read a file line by line in Python
Defaultdict in Python
Different ways to create Pandas Dataframe
Python program to convert a list to string
Defaultdict in Python
Python | Get dictionary keys as a list
Python | Split string into list of characters
Python program to check whether a number is Prime or not
Program to multiply two strings and return result as string in C++

Suppose we have two numbers as string. We have to multiply them and return the result also in string. So if the numbers are “28” and “25”, then the result will be “700”
To solve this, we will follow these steps −
Taking two arguments x and y it indicates x divides y
Taking two arguments x and y it indicates x divides y
if x < −Infinity and y = 1, then return infinity
if x < −Infinity and y = 1, then return infinity
a := |x|, b := |y| and ans := 0
a := |x|, b := |y| and ans := 0
while a − b >= 0p := 0while a − (left shifted b (left shifted 1 p times)) >= 0p := p + 1a := a − (left shift b, p times)ans := ans + left shift 1 p times
while a − b >= 0
p := 0
p := 0
while a − (left shifted b (left shifted 1 p times)) >= 0p := p + 1
while a − (left shifted b (left shifted 1 p times)) >= 0
p := p + 1
p := p + 1
a := a − (left shift b, p times)
a := a − (left shift b, p times)
ans := ans + left shift 1 p times
ans := ans + left shift 1 p times
if x > 0 is true and y > 0 is also true, then return ans, otherwise return (− ans)
if x > 0 is true and y > 0 is also true, then return ans, otherwise return (− ans)
Let us see the following implementation to get better understanding −
 Live Demo
#include <bits/stdc++.h>
using namespace std;
class Solution {
   public:
   string multiply(string num1, string num2);
};
string Solution::multiply(string nums1, string nums2) {
   int n = nums1.size();
   int m = nums2.size();
   string ans(n + m, '0');
   for(int i = n - 1; i>=0; i−−){
      for(int j = m - 1; j >= 0; j−−){
         int p = (nums1[i] − '0') * (nums2[j] − '0') + (ans[i + j +
         1] − '0');
         ans[i+j+1] = p % 10 + '0';
         ans[i+j] += p / 10 ;
      }
   }
   for(int i = 0; i < m + n; i++){
      if(ans[i] !='0')return ans.substr(i);
   }
   return "0";
}
main(){
   Solution ob;
   cout << ob.multiply("28", "25");
}
"28", "25"
"700"
How to add separator in a ToolBar with Java?

To add a separator, use the addSeparator() method. Let us first create a toolbar −
JToolBar toolbar = new JToolBar();
Now, we will create some components and set a separator to separate them as shown below −
toolbar.add(new JTextArea(" Add name here"));
toolbar.add(new JButton("Submit Name"));
toolbar.addSeparator();
toolbar.add(new JTextArea(" Add age here"));
toolbar.add(new JButton("Submit Age"));
The following is an example to add separator in a ToolBar with Java −
package my;
import java.awt.BorderLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JToolBar;
public class SwingDemo {
   public static void main(String[] args) {
      JPanel panel = new JPanel(new BorderLayout());
      JToolBar toolbar = new JToolBar();
      panel.add(toolbar, BorderLayout.PAGE_START);
      toolbar.add(new JTextArea(" Add name here"));
      toolbar.add(new JButton("Submit Name"));
      toolbar.addSeparator();
      toolbar.add(new JTextArea(" Add age here"));
      toolbar.add(new JButton("Submit Age"));
      toolbar.add(new JButton("Clear"));
      toolbar.add(new JButton("Refresh"));
      toolbar.addSeparator();
      JFrame frame = new JFrame(BorderLayout.PAGE_START);
      frame.setTitle("Separator");
      frame.setContentPane(panel);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setLocationByPlatform(true);
      frame.pack();
      frame.setSize(550, 200);
      frame.setVisible(true);
   }
}
Sort array by year and month JavaScript

We have an array like this −
const arr = [{
   year: 2020,
   month: 'January'
}, {
   year: 2017,
   month: 'March'
}, {
   year: 2010,
   month: 'January'
}, {
   year: 2010,
   month: 'December'
}, {
   year: 2020,
   month: 'April'
}, {
   year: 2017,
   month: 'August'
}, {
   year: 2010,
   month: 'February'
}, {
   year: 2020,
   month: 'October'
}, {
   year: 2017,
   month: 'June'
}]
We have to sort this array according to years in ascending order (increasing order). Moreover, if
there exist two objects with the same year property, then we have to sort those years according
to month (like jan, then feb, then march and so on).
So, let’s write the code for this sorting problem. The complete code for this will be −
const arr = [{
   year: 2020,
   month: 'January'
}, {
   year: 2017,
   month: 'March'
}, {
   year: 2010,
   month: 'January'
}, {
   year: 2010,
   month: 'December'
}, {
   year: 2020,
   month: 'April'
}, {
   year: 2017,
   month: 'August'
}, {
   year: 2010,
   month: 'February'
}, {
   year: 2020,
   month: 'October'
}, {
   year: 2017,
   month: 'June'
}]
const months = ['January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December'];
const sorter = (a, b) => {
   if(a.year !== b.year){
      return a.year - b.year;
   }else{
      return months.indexOf(a.month) - months.indexOf(b.month);
   };
};
arr.sort(sorter);
console.log(arr);
We check if the years are different, we just sort them according to years, but when the years are
the same, we check for months taking help of the custom months array we defined and this
way, objects with the same year get sorted according to months.
The output in the console will be −
[
   { year: 2010, month: 'January' },
   { year: 2010, month: 'February' },
   { year: 2010, month: 'December' },
   { year: 2017, month: 'March' },
   { year: 2017, month: 'June' },
   { year: 2017, month: 'August' },
   { year: 2020, month: 'January' },
   { year: 2020, month: 'April' },
   { year: 2020, month: 'October' }
]
How to create a link from a text using JavaScript?

To create a link, use the JavaScript link() method. This method creates an HTML hypertext link that requests another URL. The following is the syntax:
string.link( hrefname )
Above, hrefname is any string that specifies the HREF of the <a> tag; it should be a valid URL.
You can try to run the following code to learn how to work with link() method in JavaScript −
Live Demo
<html>
   <head>
      <title>JavaScript String link() Method</title>
   </head>

   <body>
      <script>
         var str = new String("Simply Easy Learning");
         var URL = "http://www.tutorialspoint.com";
         document.write(str.link( URL ));
      </script>
   </body>
</html>
Fast average of two numbers without division - GeeksforGeeks

24 May, 2021
Given two numbers, find floor of their average without using division.
Input : x = 10, y = 12
Output : 11

Input : x = 10, y = 7
Output : 8
We take floor of sum.
The idea is to use right shift operator, instead of doing (x + y)/2, we do (x + y) >> 1  
C++
C
Java
Python3
C#
PHP
Javascript
// C++ program to find average without using// division.#include <bits/stdc++.h>using namespace std; int floorAvg(int x, int y) {     return (x + y) >> 1; } int main() {  int x = 10, y = 20;  cout << "Average = " << floorAvg(x, y) <<endl;  return 0;} // This code is contributed by famously.
// C program to find average without using// division.#include <stdio.h> int floorAvg(int x, int y) {     return (x + y) >> 1; } int main() {  int x = 10, y = 20;  printf("\n\nAverage = %d\n\n", floorAvg(x, y));  return 0;}
// Java program to find average// without using divisionclass GFG{    static int floorAvg(int x, int y) {    return (x + y) >> 1; }         // Driver code    public static void main (String[] args)    {        int x = 10, y = 20;        System.out.print(floorAvg(x, y));    }} // This code is contributed by Anant Agarwal.
# Python3 program to find average# without using division.def floorAvg(x, y):    return (x + y) >> 1 # Driver codex = 10y = 20 print("Average ", floorAvg(x, y)) # This code is contributed by sunny singh
// C# program to find average// without using divisionusing System; class GFG{    static int floorAvg(int x, int y)    {      return (x + y) >> 1;    }         // Driver code    public static void Main (String[] args)    {        int x = 10, y = 20;        Console.Write("Average = ");        Console.Write(floorAvg(x, y));    }} // This code is contributed by parashar...
<?php// PHP program to find average// without using division. // function returns// the averagefunction floorAvg($x, $y){    return ($x + $y) >> 1;     }     // Driver Code    $x = 10;    $y = 20;    echo "Average = ", floorAvg($x, $y); // This Code is contributed by Ajit?>
<script> // Javascript program to find// average without using// division.function floorAvg(x, y){    return (x + y) >> 1;} // Driver codevar x = 10, y = 20; document.write("Average = " + floorAvg(x, y)); // This code is contributed by noob2000 </script>
Average = 15
 
Applications : We need floor of average of two numbers in many standard algorithms like Merge Sort, Binary Search, etc. Since we use bitwise operator instead of division, the above way of finding average is faster. 
parashar
dextarJU
jit_t
noob2000
famously
Bit Magic
Bit Magic
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Set, Clear and Toggle a given bit of a number in C
Find the size of Largest Subset with positive Bitwise AND
Check whether bitwise AND of a number with any subset of an array is zero or not
Write an Efficient Method to Check if a Number is Multiple of 3
Highest power of 2 less than or equal to given number
Swap two nibbles in a byte
Swap bits in a given number
Check for Integer Overflow
Reverse actual bits of the given number
Find one extra character in a string
Python string | ascii_uppercase - GeeksforGeeks

16 Oct, 2018
In Python3, ascii_uppercase is a pre-initialized string used as string constant. In Python, string ascii_uppercase will give the uppercase letters ‘ABCDEFGHIJKLMNOPQRSTUVWXYZ’.
Syntax : string.ascii_uppercase
Parameters: Doesn’t take any parameter, since it’s not a function.
Returns: Return all uppercase letters.
Note: Make sure to import string library function inorder to use ascii_lowercase.
Code #1 :
# import string library function import string     # Storing the value in variable result result = string.ascii_uppercase     # Printing the value print(result) 
Output :
ABCDEFGHIJKLMNOPQRSTUVWXYZ
 
Code #2 : Given code checks if the string input has only upper ASCII characters.
# importing string library function import string      # Function checks if input string # has upper ascii letters or not def check(value):     for letter in value:                      # If anything other than upper ascii         # letter is present, then return         # False, else return True         if letter not in string.ascii_uppercase:             return False    return True     # Driver Code input1 = "GeeksForGeeks"print(input1, "--> ",  check(input1))      input2 = "GEEKS FOR GEEKS"print(input2, "--> ", check(input2))      input3 = "GEEKSFORGEEKS"print(input3, "--> ", check(input3)) 
Output:
GeeksForGeeks -->  False
GEEKS FOR GEEKS -->  False
GEEKSFORGEEKS -->  True
Applications :The string constant ascii_uppercase can be used in many practical applications. Let’s see a code explaining how to use ascii_uppercase to generate strong random passwords of given size.
# Importing random to generate # random string sequence import random     # Importing string library function import string     def rand_pass(size):             # Takes random choices from     # ascii_letters and digits     generate_pass = ''.join([random.choice(                         string.ascii_uppercase + string.digits)                         for n in range(size)])                                 return generate_pass     # Driver Code  password = rand_pass(10) print(password)       
Output:
TR2ESZAJOT
python-string
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python Dictionary
Read a file line by line in Python
How to Install PIP on Windows ?
Enumerate() in Python
Different ways to create Pandas Dataframe
Iterate over a list in Python
Python String | replace()
*args and **kwargs in Python
Reading and Writing to text files in Python
Create a Pandas DataFrame from Lists
How to wrap multiple divs in one with jQuery?

To wrap multiple divs in one with jQuery, use the wrapAll() method. You can try to run the following code to wrap multiple divs in one with jQuery −
Live Demo
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
   $("#button1").click(function(){
      $('.b,.c').wrapAll('<div class="wrap"></div>');  
   });
});
</script>
<style>
.wrap {
  color:blue;
}
</style>
</head>
<body>
 <div class='a'>This is div 1</div>
 <div class='b'>This is div 2</div>
 <div class='c'>This is div 3</div>
<button id="button1">Wrap</button>
</body>
</html>