Question
Write a static void method printNums with int array parameter that prints out all the elements of the parameter on one line, blank separated. Use
-
Write a static void method printNums with int array parameter that prints out all the elements of the parameter on one line, blank separated. Use it for tests of methods below.
-
Write a program NoNegTest.java including a static void method called noNeg to mutate its int array parameter so all negative elements become 0. Include a test in main. For your tests remember the easy way to initialize an array with braces.
-
Write a program AllUpperTest.java including a static method called allUpper with a String array parameter that does not modify the parameter array, but returns a String array with all the strings of the parameter array in upper case. (Use string method toUpperCase: "Hello".toUpperCase() returns "HELLO".) Include a test in main. Use a for-each loop to display the contents of the returned array.
-
Write a program TestIncreasing.java including a static boolean method called isIncreasing with an int array parameter that returns true if the array elements are strictly increasing, and false otherwise. Include thorough tests in main. It is easy not to have diverse enough tests!
-
Write a program TestIntFactorial.java the body of
public static int factorial(int n)
where factorial(n), or n! in math, means 1*2*...*n for positive n. By convention 0! is 1. 1! is 1; 2! is 1 * 2 = 2; 3! is 1*2*3 = 6.
What is the largest value of n for which you get the correct answer in Java? (In Python there is no limit until you run out of system memory.) If you get a negative answer, it is clearly screwy, but overflow answers do not need to be negative. You might write some extra code to help with the test (not necessarily in your final program -- maybe just tested in jshell).
After figuring out the answer to this question, in your main method do label and show the call to factorial with the largest int that works. Also label and show the result for the next int, with the wrong answer.
-
Same as the last problem by with int type everywhere replaced by long, in program TestLongFactorial.java
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started