[output] | public class Sum { public static void main(String[] args) { int num = 10; int sum = 0; for (int i = 1; i <= num; i++) { sum += i; } System.out.println("Sum of natural numbers from 1 to " + num + " is " + sum); } } [instruction] | Using Java, write a program to find the sum of natural numbers from 1 to an input number. [input] | 10
[output] | 4 > 5 [instruction] | Write a boolean expression for the statement "4 is greater than 5". [input] |
[output] | #include <iostream> int main() { for(int i = 1; i <= 100; i++) { std::cout << i << ' '; } return 0; } [instruction] | Write a loop in C++ to print out a list of numbers from 1 to 100. [input] |
[output] | SELECT * FROM product; [instruction] | Write the SQL query to print out all the products in the product table. [input] |
[output] | function calcAvg(arr) { let sum = 0; let arrLength = arr.length - 1; for(let i = 0; i < arrLength; i++) { sum += arr[i]; } return sum / arrLength; } [instruction] | Create a javascript function for calculating the average of 1 to n-1 numbers in an array. [input] | [1, 2, 3, 4]
[output] | print("Hello World") [instruction] | Generate a python statement to print out "Hello World". [input] |
[output] | <div style="width: 500px;"> <span>Important</span> </div> [instruction] | Write a CSS code to create a div container with a width of 500px and a label "Important". [input] |
[output] | def num_common_characters(str1, str2): char_count = {} for c in str1: if c in str2: if c not in char_count: char_count[c] = 1 else: char_count[c] += 1 return sum(char_count.values()) [instruction] | Given two strings, write a program to find the number of common characters. [input] | string_1 = "computer" string_2 = "science"
[output] | Valid identifier names for JavaScript variables must start with a letter, underscore (_), or dollar sign ($); can contain alphanumeric characters and underscore; and must not contain spaces, start with a number or a keyword (such as "var"). Examples of valid variable names include "myVar", "$_1stNam [instruction] | Given a JavaScript code, what are valid identifier names for its variables? [input] |
[output] | function avgTwoNums(num1, num2) { const average = (num1 + num2) / 2; return average; } [instruction] | Generate a JavaScript function to return the average of two numbers [input] |
[output] | The type of input required for this Python function is two numerical values (for example, integers or floats). [instruction] | Identify the type of input that is required for this Python function. [input] | def get_sum(a, b): # return the sum of two numbers
[output] | # Function to calculate the sum of all even numbers between 0 and 10 def sum_even sum = 0 (0..10).each do |even_number| if even_number % 2 == 0 sum += even_number end end sum end # Invoke the function sum_even [instruction] | Generate a Ruby program which returns the sum of all even numbers between 0 and 10 [input] |
[output] | <html> <head> <title> Sample Table </title> </head> <body> <h1>My Sample Table</h1> <table> <thead> <tr> <th>Col1</th> <th>Col2</th> </tr> </thead> <tbody> <tr> <td>Row1Value1</td> <td>Row1Value2</td> </tr> </tbody> </ta [instruction] | Write an HTML program to display a web page with a table, a heading, and a div [input] |
[output] | let arrayObjects = [ {name: 'Spike', age: 6}, {name: 'Spot', age: 4}, {name: 'Max', age: 2}, {name: 'Fluffy', age: 8} ]; [instruction] | Create a array of objects in JavaScript. [input] |
[output] | const http = require('http'); const requestListener = function (req, res) { res.end('Hello World!'); }; const server = http.createServer(requestListener); server.listen(3000); [instruction] | Write a Node.js server program to handle HTTP requests to a web page. [input] |
[output] | .styled-link { color: #00b3e6; text-decoration: none; font-weight: bold; } [instruction] | Create a CSS class to style an anchor tag. [input] |
[output] | { "deleted": true, "name": "John Doe", "email": "john.doe@example.com", "age": 32, "gender": "Male" } [instruction] | Create a JSON object to represent a profile deleted from a social platform. [input] |
[output] | <form> <label for="email">Email:</label> <input type="email" id="email" placeholder="Email"/> <input type="submit" value="Submit"/> </form> [instruction] | Create a HTML form with an email input field. [input] |
[output] | This JavaScript promise chain prints out the following output: 1 2 4 The first console.log() logs the result of the first promise when it resolves, which is the number 1. The second console.log() logs the result of the second promise when it resolves, which is the number 2 (1 * 2). The third cons [instruction] | Execute this JavaScript Promise chain and explain the output. [input] | new Promise((resolve, reject) => { setTimeout(() => { resolve(1); }, 1000); }).then((result) => { console.log(result); // 1 return new Promise((resolve, reject) => { setTimeout(() => { resolve(result * 2); }, 1000); }); }).then((result) => { console.log(result); // 2
[output] | const axios = require('axios'); axios.get('https://api.github.com/search/repositories?q=language:javascript&sort=stars&order=desc&per_page=100') .then(function (response) { let repos = response.data.items.filter(repo => repo.language === 'JavaScript' && new Date(repo.created_at) [instruction] | Write a Node.js code to get a list of the most starred Node.js repositories on github in the last month. [input] |
[output] | import java.util.Scanner; public class ReverseString { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter a string: "); String str = in.nextLine(); in.close(); char[] arr = str.toCharArray(); [instruction] | Write a Java code to read a string from the user and print it reversed. [input] |
[output] | SELECT * FROM users WHERE date_of_birth < '1989-02-17'; [instruction] | Create a SQL query to select users born before 1989-02-17. [input] |
[output] | import java.util.ArrayList; public class GenerateStrings { public static ArrayList<String> generateStrings(int n){ ArrayList<String> stringList = new ArrayList<>(); char[] string = new char[n]; generateStringUtil(string, n, 0, stringList); return stringList; } [instruction] | Write a function in Java to generate all possible strings of length n drawn from 0–9. [input] |
[output] | import requests from bs4 import BeautifulSoup url = "https://www.example.com/" response = requests.get(url) soup = BeautifulSoup(response.text, "html.parser") # extract information from HTML data = soup.find_all("div", {"class": "content"}) # save scraped data with open('filename.txt', 'w') as f [instruction] | Create a Python script to scrape HTML data from a website. [input] |
[output] | def get_longest_sentence(lst): longest_sentence = '' longest_len = 0 for s in lst: s_len = len(s) if s_len > longest_len: longest_sentence = s longest_len = s_len return longest_sentence if __name__ == '__main__': lst = ['This sentence is [instruction] | Generate a code to take in a list of sentences, totaling no more than 100 words and output the longest sentence. [input] | ['This sentence is the longest.', 'This sentence is the shortest.']
[output] | SELECT * FROM table_name ORDER BY id DESC LIMIT 1; [instruction] | What MySQL query can be used to retrieve the most recent record in a table? [input] |
[output] | SELECT c.first_name, c.last_name, c.street, c.city, c.state, c.zip FROM customers c INNER JOIN orders o ON c.customer_id = o.customer_id INNER JOIN order_items oi ON o.order_id = oi.order_id WHERE oi.price > 50 [instruction] | Create a SQL query to find the names and addresses of customers who have purchased a product that is priced more than $50. [input] | TABLE customers Columns: * customer_id * first_name * last_name * street * city * state * zip TABLE orders Columns: * order_id * customer_id * order_date TABLE order_items Columns: * order_item_id * order_id * product_id * quantity * price
[output] | The forEach() method in Javascript is used to iterate over each element in an array. It takes a callback function as an argument which is executed for each element of the array. The syntax of the forEach() method is as follows: array.forEach(function(element, index, array) { // code to be executed [instruction] | Describe the purpose and syntax of the 'forEach' method in Javascript. [input] |
[output] | SELECT c.customer_id, c.first_name, c.last_name FROM customers c LEFT JOIN orders o ON c.customer_id = o.customer_id WHERE o.customer_id IS NULL [instruction] | Write an SQL query to find all customers who have not placed any orders. [input] | TABLE customers Columns: * customer_id * first_name * last_name TABLE orders Columns: * order_id * customer_id * order_date
[output] | Two ways to prevent SQL injection are parameterized queries and escaping user input. Parameterized queries use placeholders to define the data that will be inserted into the query. This prevents any malicious data from being added as it will be treated as an ordinary string. Escaping user input is a [instruction] | Describe two ways to prevent SQL injection. [input] |