please fidn the code 1
import java.util.ArrayList;
import java.util.Scanner;
public class Triangular {
public static void main(String args[]){
Scanner sc = new
Scanner(System.in);
System.out.print("Enter the size of
the list: ");
int size = sc.nextInt();
ArrayList<Integer> list =
triangular(size);
System.out.println(list.toString());
}
public static ArrayList<Integer> triangular(int
n){
int sum=0;
ArrayList<Integer> list1 =
new ArrayList<Integer>();
if(n<=0)
return
list1;
else{
for(int
i=0;i<n;i++){
sum = sum+(i+1);
list1.add(sum);
}
}
return list1;
}
}
2) mthod for sum list
private static int sumList(ArrayList lis1){
int sum=0;
for(int
i=0;i<lis1.size();i++){
sum = sum +
(Integer)lis1.get(i);
}
return sum;
}
Function name: triangular Parameters: integer Returns: a list Description: Write a function called triangular that accepts...
Write a method maxOccurrences that accepts a list of integers as a parameter and returns the number of times the most frequently occurring integer (the “mode”) occurs in the list. Solve this problem using a map as auxiliary storage. If the list is empty, return 0.
1. Write a function called ordinal_sum that accepts a string argument and returns the sum of the ordinal values of each character in the string. The ordinal value of a character is its numeric Unicode code point in decimal. 2. Write code that creates a Python set containing each unique character in a string named my_string. For example, if the string is 'hello', the set would be {'h', 'e', 'l', 'o'} (in any order). Assign the set to a variable...
Sum of Numbers Problem: Write a method that accepts an integer argument and returns the sum of all the integers from 1 up to the number passed as an argument. For example, if 50 is passed as an argument, the method will return the sum of 1, 2, 3, 4, . . . 50. Use recursion to calculate the sum. Demonstrate the method in a program. The program should be called SumOfNumbers.java.
java /* Q2 (10 pts): Write a method called method that accepts an integer parameter * * * * and returns a sum of the first n terms of the sequence. * In other words, the method should generate the following sequence: 1 + 1/2 + 1/3 + 1/4 + ... 1/n * For example, method2(2) will return 1.5 since 1+1/2 = 1.5 * method2 (15) will return 3.3182289932289937 * You may assume that the parameter n is nonnegative. */...
I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that accepts one integer parameter and returns the value raised to the third power as an integer. o Write a method called randominRange that accepts two integer parameters representing a range. The method returns a random integer in the specified range inclusive. 2. o Write a method...
Python Function Name: sign_count Parameters: a list of integers Returns: an integer Description: Speed signs should be posted every mile on a given street. You are given a list of 0s & 1s, where each number represents a quarter of a mile. Thus, every 4 zeroes requires a speed sign. However, a 1 indicates an intersection, and each intersection is automatically required to have a speed limit sign. A sign for each mile proceeds as usual after the intersection. Your...
Using Java: 1. Recursive Multiplication Write a recursive function that accepts two arguments into the parameters x and y. The function should return the value of x times y. Remember, multiplication can be performed as repeated addition as follows: 5×6=6+6+6+6+6 2. Recursive findings Write a recursive boolean method named reFinding. The method should search an array for a specified value, and return true if the value is found in the array, or false if the value is not found in...
IN PYTHON: Write a function that takes, as an argument, a positive integer n, and returns a LIST consisting of all of the digits of n (as integers) in the same order. Name this function intToList(n). For example, intToList(123) should return the list [1,2,3].
/* Write a recursive function named editDistance that accepts two string * parameters and returns the "edit distance" between the two strings as an * integer. Edit distance (also called Levenshtein distance) is the minimum * number of "changes" required to get from s1 to s2 or vice versa. A "change" * is a) inserting a character, * b) deleting a character, or * c) changing a character to a different character. *...
Function Name: zip_d Parameters: two equal-sized lists Returns: a dictionary Description: Write a function, zip_d, that takes a two equal-sized lists as parameters, and zips each list into a dictionary. Sample Inputs/Outputs: Example Call: zip_d([1,2,3], ['a','b','c']) Expected Return: {1: 'a', 2: 'b', 3: 'c'} Example Call: zip_d([‘a’,’b’,’c’],[9.8,7.6,5.4]) Expected Return: {‘a’:9.8, ’b’:7.6, ’c’:5.4} please answer in python