Write program in JAVA with a method that returns an array. The method should accept as input a comma-delimited string with three values from a user. The array should store each value in a different element. Use Try..Catch error handling and print any failure messages, or print success from within method if execution is successful (see Chapter 13 in the text). Call the method from the main method of the program to demonstrate its functionality by looping through the array and printing the individual values. Submit your source code and screenshots of the application executing the application and the results in a single document.
import java.util.Scanner; public class CommaSeparatedArray { public static String[] splitString(String s) { String[] words = s.split(","); for (int i = 0; i < words.length; i++) { words[i] = words[i].trim(); } System.out.println("success"); return words; } public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter a command separated line: "); String[] words = splitString(in.nextLine()); System.out.println("Words are"); for (int i = 0; i < words.length; i++) { System.out.println(words[i]); } in.close(); } }
separated line: suCCess Words are how you?
Write program in JAVA with a method that returns an array. The method should accept as input a co...
Write a Java program that takes an int array as input, and returns the average of all the values in the array. No class construction is necessary; however, the complete signature and definition and brief documents are needed.
Develop a Java application that provides program output in a logical manner and incorporates appropriate data types. Similar to zyBooks examples in Chapter 2, your program should prompt a user to enter a car brand, model, year, starting odometer reading, ending odometer reading, and gallons used. The output should include this information along with the estimated miles per gallon consumed by the vehicle in the format MPG: your calculation. Print each on separate lines with the appropriate labels (example, MPG:...
Write a complete JAVA program to do the following program. The main program calls a method to read in (from an input file) a set of people's three-digit ID numbers and their donations to a charity (hint: use parallel arrays)Then the main program calls a method to sort the ID numbers into numerical order, being sure to carry along the corresponding donations. The main program then calls a method to print the sorted 1ists in tabular form, giving both ID...
Write a Java program that will create an array of Strings with 25 elements. Input Strings from the user and store them in the array until either the user enters “quit” or the array is full. HINT: the sentinel value is “quit” all lowercase. “Quit” or “QUIT” should not stop the loop. HINT: you have to use the equals method (not ==) when you are comparing two Strings. After the input is complete, print the Strings that the user entered...
write a java program Accept a positive integer n from keyboard and then create an array or arraylist containing n random elements within the range [-n,n). Print out the random array or arraylist, and then find out and print out the number of inversions and the maximum subarray (index range of the maximum subarray along with the maximum subarray sum) in the array or arraylist using divide and conquer, respectively. For example, suppose we accept integer 6 from keyboard, then...
Write a java Program Initialize Array. Write a Java method initArray() with the following header to initialize a one-dimensional array a such that the element values (integers) are twice the index value. For example, if i = 23, then a23 = 46. The function is void with one parameter -- the integer array of a[]. Then write a main() with an int[] array2i size 100 to call
Write a program that creates an array of 10 integers. The array should be populated with values: each element should be equal to its subscript/index. The program should then print each element. Make use of a loop in storing values to the array. Make use of another loop in printing the values of the array.
Write a JAVA program with methods that initializes an array with 20 random integers between 1 and 50 and then prints four lines of output, containing 1)The initialized array. 2)Every element at an even index. 3)Every even element. 4)All elements in reverse order. Requirements (and hints): 1. Build a method that takes any integer array as input and prints the elements of the array. ALL printing in this lab must be done using a call to the printArray method and...
Write a program that deletes an element of a one-dimensional array of characters. The program should: Ask user to input the number of characters in the array the values of the array a character to be deleted Call a method to delete the character Print the resulting array or, if the character is not found, print “Value not found” The method called by the main program should: Pass the array and the character to be found as parameters If the...
JAVA / please add comments Write code for a method named loadDatagrams() that returns an array of type Datagram. The method will read from the filepath C:/folder/grams.dgf and the file contains an array of type Datagram ( you may assume that the class definition is visible to the method) Remember to include appropriate exception handling