← 목록

Synth · CodeAlpaca일부

총 20,022개 · 페이지 644/668
🔀 랜덤
불러오는 중…

[output] | public class TestArrayLength { public static void printLength(int[] array) { System.out.println("The length of the array is: " + array.length); } public static void main(String[] args) { int[] numbers = {1, 2, 3, 4, 5}; printLength(numbers); } } [instruction] | Write a Java program that passes an array to a method and prints its length. [input] |

[output] | Dynamic Programming (DP) is an algorithmic technique used to solve optimization problems. Specifically, the Knapsack problem is a popular problem which is solved using the DP approach. The idea is to solve the problem by breaking it into smaller sub-problems and storing the results of each subproble [instruction] | Describe the Dynamic Programming approach used to solve the Knapsack problem. [input] |

[output] | def capitalize_string(string): return string[0].upper() + string[1:] [instruction] | Write a function which takes a string as an argument and returns the same string with the first letter capitalized. [input] | 'hello world'

[output] | function findPerfectNumbers(n) { var perfects = []; for(var i = 1; i<=n; i++){ var divisorsSum = 0; for(var j = 1; j<i; j++){ if(i % j == 0){ divisorsSum += j; } } if(divisorsSum == i){ perfects.push(i); } } return perfects; } [instruction] | Construct a function in JavaScript to find all the Perfect Numbers up to the given parameter n. [input] |

[output] | # Finds two numbers in an array that have the largest sum def getMaxSum(arr): # Initialize the sum to the maximum possible value maxSum = -float('inf') # Iterate over all elements of the array for i in range(len(arr)): for j in range(i+1, len(arr)): # Compare the current sum to the max [instruction] | Design an algorithm to find the two numbers in an array that have the largest sum. [input] | [1,3,4,6,7]

[output] | def printSpiral(arr): # track the current row and columns cur_row = 0 cur_col = 0 # track the starting and ending columns of the row and rows of the column start_col = 0 end_col = len(arr[0]) - 1 start_row = 0 end_row = len(arr) - 1 while start_col <= en [instruction] | Generate a function which takes a two-dimensional array of integers as an argument and prints out the elements in spiral order. [input] | [[1,2,3], [4,5,6], [7,8,9]]

[output] | string = 'hello world' string = string.upper() print(string) [instruction] | Modify the code in Python to convert a lower case string to an upper case string. [input] | 'hello world'

[output] | def queryTable(query): conn = sqlite3.connect('database.db') cursor = conn.cursor() cursor.execute(query) data = cursor.fetchall() # print table header for column in data[0].keys(): print(column.center(50), end = ' | ') print('\n') # print table data for [instruction] | Write a function that takes a SQL query as an argument and prints out the results of the query in a tabular format. [input] | SELECT * FROM tableA

[output] | import java.util.Stack; public class TowerOfHanoi { public static void towersOfHanoi(int disks) { Stack<Integer> source = new Stack<Integer>(); Stack<Integer> destination = new Stack<Integer>(); Stack<Integer> auxillary = new Stack<Integer>(); int i, total [instruction] | Construct a program in Java for solving the Tower of Hanoi puzzle. [input] |

[output] | //recursive approach Node *deleteKey(Node *head, int k) { Node *curr = head; if (curr == NULL) return NULL; // check for head node if (curr->key == k) { Node *temp = curr; head = curr->next; free(temp); return deleteKey(head, k); [instruction] | Design an algorithm to delete all occurrences of a given key k in a singly linked list. [input] |

[output] | def generate_shopping_list(): list_items = ['Bread', 'Milk', 'Butter', 'Eggs', 'Cereal', 'Fruits', 'Veggies', 'Canned food', 'Frozen food', 'Cheese', 'Meat', 'Snacks', 'Coffee', 'Tea', 'Sugar', 'Salt', 'Herbs', 'Cooking oil', 'Detergent', 'Toilet paper'] return list_items [instruction] | Generate a general shopping list using Python. [input] |

[output] | public class Sum{ public static void main(String args[]) { int a = 2; int b = 5; int c = 8; int d = 10; int e = 13; int sum = a + b + c + d + e; System.out.println("Sum = " + sum); } } [instruction] | Create a program using Java to print the sum of the following five numbers. [input] | int a = 2; int b = 5; int c = 8; int d = 10; int e = 13;

[output] | def calculator(A, B, C): add = A + B subtract = A - B multiply = A * C divide = A / B remainder = A % B return add, subtract, multiply, divide, remainder [instruction] | Create a calculator program using Python to do the following calculations. [input] | A = 30; B = 15; C = 4;

[output] | for i in range (0, len(string), 2): print(string[i], end = '') [instruction] | Create a for loop to print every other letter in a given string. [input] | string = "Logic speaks to reason, not to the imagination"

[output] | def factor_list(number): factors = [] i = 2 while i * i <= number: if number % i: i += 1 else: number //= i factors.append(i) if number > 1: factors.append(number) return factors [instruction] | Generate a function to create a list of factors for a given integer. [input] |

[output] | def count_non_printable_characters(string): non_printable = ''.join(chr(i) for i in range(0, 32)) counter = 0 for char in string: if char in non_printable: counter+= 1 return counter [instruction] | Write a function that takes an input string and finds the number of non-printable characters. [input] |

[output] | def has_unique_characters(string): return len(string) == len(set(string)) [instruction] | Create a function to check if an input string has unique characters or not. [input] | string = "unique"

[output] | def boolean_search(list_of_numbers): result_array = [] for elem in list_of_numbers: result_array.append(elem in list_of_numbers) return result_array [instruction] | Generate a python code that takes a list of integers, prints out an array that is all True if the values are in the input list and all False otherwise. [input] | list_of_numbers = [5, 7, 10, 2]

[output] | def reverse_in_place(string): return string[::-1] [instruction] | Implement a Python code that takes a string and reverses the characters in place. [input] | string = "This is easy"

[output] | def min_max(list_of_numbers): min = list_of_numbers[0] max = list_of_numbers[0] for number in list_of_numbers: if number > max: max = number elif number < min: min = number return min, max [instruction] | Modify the program to take a given list of integers and returns the maximum and minimum values. [input] | list_of_numbers = [3, 8, -1, 5]

[output] | floating-point number [instruction] | Categorize each of the following strings as a floating-point number, integer, or string. [input] | 59689.14

[output] | No errors have been found in the code. [instruction] | Test the following Python code for any errors. [input] | def calculate_mean(numbers): total_sum = 0; for n in numbers: total_sum += n mean = total_sum / 10 # length of numbers

[output] | public class HelloWorld { public static void main(String[] args) { System.out.println("Hello world); } } [instruction] | Modify the following Java code to debug and execute properly. [input] | public class HelloWorld { public static void main(String[] args) { System.out.print("Hello world); } }

[output] | import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class DatabaseRetrieve { private Connection connection; private String query; public DatabaseRetrieve(Connection connection, String query) { this.connection = [instruction] | Generate a class in Java for retrieving data from a database. [input] |

[output] | ^[0-9]{3}-?[0-9]{3}-?[0-9]{4}$ [instruction] | Develop a regex pattern to match any valid phone number. [input] |

[output] | my_dict = {'a': 1, 'b': 2, 'c': 3, 'd': 4} # remove element 'd' my_dict.pop('d', None) # print resulting dictionary print(my_dict) # Output: {'a': 1, 'b': 2, 'c': 3} [instruction] | Develop a Python program to remove elements from a dictionary. [input] | my_dict = {'a': 1, 'b': 2, 'c': 3, 'd': 4}

[output] | """ Change a string to have its first letter capitalized and the remaining characters in lower case """ def capitalize_string(s): return s[0].upper() + s[1:].lower() if __name__ == '__main__': print(capitalize_string('mySTRING')) [instruction] | Write a code to change a string to have its first letter capitalized and the remaining characters in lower case. [input] | mySTRING

[output] | """ Create a script that can predict the next letter in a given string of text """ import tensorflow as tf from tensorflow.keras.preprocessing.sequence import pad_sequences def predict_next_letter(text): data = [ord(char) for char in text] data = pad_sequences([data], maxlen=10, truncating='pos [instruction] | Create a script that can predict the next letter in a given string of text. [input] | Hello

[output] | """ Parse an XML document and return a JSON object containing the data """ import xml.etree.ElementTree as ET import json def parse_xml(xml_string): root = ET.fromstring(xml_string) book = {} for child in root: book[child.tag] = child.text return json.dumps(book) if __name__ [instruction] | Parse an XML document and return a JSON object containing the data. [input] | <book> <title>Cat in the Hat</title> <author>Dr. Seuss</author> <year>1957</year> </book>

[output] | """ Create a deep learning model to output a sentence in French when given an English sentence as input """ import tensorflow as tf import numpy as np # Input and output languages input_lang = 'EN' output_lang = 'FR' # Define the model model = tf.keras.Sequential([ tf.keras.layers.Embedding(inpu [instruction] | Create a deep learning model to output a sentence in French when given an English sentence as input. [input] | I like to eat apples.

← → 방향키로 페이지 이동 · 숫자 입력 후 Enter로 점프