[output] | public class Swap { public static void main(String[] args) { int a = 10; int b = 20; System.out.println("before swap: a = "+a+" b = "+b); int temp = a; a = b; b = temp; System.out.println("after swap: a = "+a+" b = "+b); } } [instruction] | Generate a correct Java program to swap two given numbers. [input] |
[output] | int n = 5; for (int i = n; i > 0; i--) { for(int j = 0; j < i; j++) { System.out.print("*"); } System.out.println(); } [instruction] | Edit the following code so that it prints out a right triangle of size n [input] | int n = 5; for (int i = 0; i < n; i++) { for (int j = 0; j <= i; j++) { System.out.print("*"); } System.out.println(); }
[output] | SELECT COUNT(*) FROM Customers WHERE email = 'john@example.com'; [instruction] | Generate a correct SQL query for checking if a record exists with a given condition. [input] | Check if a record exists in the "Customers" table with the email address "john@example.com";
[output] | def bin_to_hex(binary_string): dec = int(binary_string, 2) hex_string = hex(dec).replace('x', '') return hex_string [instruction] | Write a Python program to convert a given binary string to its equivalent hexadecimal representation. [input] |
[output] | SELECT Name FROM Users WHERE Gender = 'Female' [instruction] | Write a SQL query to find the names of all users where the gender is `Female`. [input] |
[output] | def merge_dicts(dic1, dic2): res = {**dic1, **dic2} return res [instruction] | Write Python code to merge two given dictionaries into a single dictionary. [input] | Dictionary 1: {'A':1, 'B':2} Dictionary 2: {'C':3, 'D':4}
[output] | largest_integer = max([1, 4, 9, 3, 5]) print(largest_integer) # Output: 9 [instruction] | Find the largest integer in this list? [input] | [1, 4, 9, 3, 5]
[output] | @RestController public class ProductController { @Autowired private ProductService productService; @GetMapping("/products") public List<Product> getProducts(){ return productService.listProducts(); } } [instruction] | Write a Spring Boot Rest Controller to list all products in an online store. [input] |
[output] | <p style="background-color:blue;">I am a paragraph</p> <p style="background-color:blue;">I am another paragraph</p> [instruction] | Change the background color of all paragraphs in HTML code to blue. [input] | <p>I am a paragraph</p> <p>I am another paragraph</p>
[output] | button { display: block; margin-left: auto; margin-right: auto; } [instruction] | Write a CSS code to align a button to the center of a webpage. [input] | <button>My Button</button>
[output] | #!/bin/bash if [ "$#" -eq 3 ] then echo "Number of Arguments provided is 3" else echo "Number of Arguments provided is not 3" fi [instruction] | Write a Bash script to check if the number of arguments supplied is equal to 3 or not. [input] |
[output] | def findAllWordsStartingWith(string,letter): words = string.split(' ') allWordsStartingWithLetter = [] for word in words: if word[0] == letter: allWordsStartingWithLetter.append(word) return allWordsStartingWithLetter print(findAllWordsStartingWith('hello world' [instruction] | Find all words that start with the letter 'R' in a string. [input] | string = "hello world"
[output] | def explode_string(given_str): return given_str.split(",") given_str = "apple,banana,orange" exploded_str = explode_string(given_str) print(exploded_str) # Output: ['apple', 'banana', 'orange'] [instruction] | Explode a string with a given delimiter. [input] | given_str = "apple,banana,orange"
[output] | class Camera: """Class representing a camera""" def __init__(self, brand, model): """""" self.brand = brand self.model = model def get_brand(self): """""" return self.brand def get_model(self): """""" return sel [instruction] | Construct a Python class for a camera object. [input] |
[output] | def binary_search(data, target): low = 0 high = len(data) - 1 while low <= high: index = (low + high) // 2 value = data[index] if value == target: return index if target < value: high = index - 1 else: low [instruction] | Program a binary search algorithm. [input] | data: [2, 4, 6, 8, 10, 12, 14, 16, 18, 20] target: 16
[output] | numbers = [1, 2, 3, 4, 5] # calculate the mean mean = sum(numbers)/len(numbers) print('The mean of the list of numbers is {}.'.format(mean)) [instruction] | Replace the "TODO" comment in this code with logic to calculate the mean of a list of numbers. [input] | numbers = [1, 2, 3, 4, 5] # TODO: calculate the mean
[output] | variable1 = 5 variable2 = 10 if variable1 > variable2: print("variable1 is greater than variable2") elif variable1 < variable2: print("variable1 is less than variable2") else: print("variable1 is equal to variable2") [instruction] | Construct an if-else statement to compare two variables. [input] | variable1: 5 variable2: 10
[output] | def foo(nums): result = [] for val in nums: val += 2 result.append(val) return result nums = [1, 2, 3, 4] result = foo(nums) [instruction] | Debug the following code and update the list "result" accordingly. [input] | def foo(nums): result = [] for val in nums: val += 2 result.append(val) return result nums = [1, 2, 3, 4]
[output] | y = 28 [instruction] | Consider the formula z=(x1n+x2+x3)(2x2+3x3)? find the value of y [input] | x1 = 2; x2 = 4; x3 = 6
[output] | This function takes two integers as input and returns their sum. [instruction] | Summarize the given code [input] | def sumOfTwo(a, b): """Returns the sum of two integers.""" c = a + b return c
[output] | def sum_values(data): """Returns the sum of values in the given dataset.""" sum = 0 for val in data: sum += val return sum [instruction] | Modify the program to work with any dataset [input] | def sum_values(data): """Returns the sum of values in the given dataset.""" sum = 0 # TODO: Your code here return sum
[output] | def sum_digits(n): s = 0 while(n): s += n % 10 n //= 10 return s print(sum_digits(155)) [instruction] | Write a Python program to calculate the sum of the digits in an integer [input] | N = 155
[output] | 24 [instruction] | Output the 5th element in an array [input] | [1, 5, 9, 17, 24, 42, 50]
[output] | def get_multiples(n, limit): """Return list of n's multiples for all numbers up to limit""" multiples = [] for i in range(limit + 1): if i % n == 0: multiples.append(i) return multiples [instruction] | Read the comment in the code and update the code accordingly. [input] | def get_multiples(n, limit): """Return list of n's multiples for all numbers up to limit""" multiples = [] # TODO: Your code here return multiples
[output] | def selection_sort(arr): for i in range(len(arr)): min_idx = i for j in range(i+1, len(arr)): if arr[min_idx] > arr[j]: min_idx = j arr[i], arr[min_idx] = arr[min_idx], arr[i] return arr print(selection_sort([4, 1, 10, 8, 5])) [instruction] | Perform a selection sort on the given array [input] | [4, 1, 10, 8, 5]
[output] | 1 [instruction] | What will be the ouptut of below operation? [input] | print(4 >> 2)
[output] | public class PrintNumbers{ public static void main(String[] args){ // Prints numbers from 1 to 100 for(int i = 1; i <= 100; i++){ System.out.println(i); } } } [instruction] | Write a Java program that prints all numbers between 1 to 100. [input] |
[output] | true [instruction] | Determine if the given input string is a valid C++ identifier or not. [input] | stringInput = "my_age"
[output] | SELECT name FROM Employees WHERE company = 'ABC'; [instruction] | Create a SQL query to show all the employees' names working in the company 'ABC'. [input] |
[output] | The <div> tag defines a division or section in the HTML document. It is used to group blocks of related elements to structure and style a page. The <div> tag is a block-level element, meaning it can stand alone and not appear within any other tags. CSS can be used along with the <div> to define des [instruction] | Explain the role of an HTML div tag. [input] |