Question: (JAVA) 1) Define a method called sum() that takes a positive int number as parameter and returns the sum of all the integers from 1
(JAVA)
1) Define a method called "sum()" that takes a positive int number as parameter and returns the sum of all the integers from 1 to number. This method performs no user input and prints no output. You can assume that his method will always recieve an integer that is greater than 0 as its parameter. Please only write the method definition, do not worry about the class that this method is inside of.
2) Write a main() program that calls the sum() method that you defined in the previous question. You program will ask the user to type a positive integer, read the user's response into an int variable, and then print the sum of all the numbers from 1 to the users number. You can assume that this main() is inside the same class that the definition of the sum() method is in above.
3) write a code that defines an arraylist of string objects. Both arraylist and string are calsses defined in the java api. Your code will do the following: 1) Define an ArrayList of String objects, 2) Create three new string objects with the following values: "First string" "Second String" "third string" 3) add these three new strings to the arraylist 4) after all three string objects are in the arraylist, print the array list to show that the strings are in the array list.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
