Question: 1 . Write a Java program A 2 p 1 . java with a public class A 2 p 1 and no named packages that

1. Write a Java program A2p1.java with a public class A2p1 and no named packages that accepts one command line argument a which is assumed to be positive integer at least 2. Calculate and print an integer list starting from a and ending until some integer appears a second time by iteratively applying a math function f to the value of a. The math function f is defined as f(x)=(3x+1)/2 if x is odd and f(x)=x/2 if x is even. The iteration will stop when some value is reached twice. For example: When a is 6, the integer list should be 6,3,5,8,4,2,1,2 and the length of this list is 8. The length of the list should also be printed. You program can, but does not have to, store all elements of the list in memory at once. A sample run can look like the following (those shown in blue color are typed by the user):
[kwang@computer][~/temp]$java A2p114
Iterated list for 14 is:
14,7,11,17,26,13,20,10,5,8,4,2,1,2
Length of the list: 14
2. Write a Java program A2p2.java with a public class A2p2 and no named packages that accepts a command line argument m that is assumed to be a multiple of 60(e.g.60,120,etc). Generate a string of m random upper case English characters and store them in a char array. Design three additional methods other than the main method each of which is supposed to convert one-third of the m chars in your array in place into a backward-offset lower case version (i.e.A->z,B->a,C->b,...,Y->x,Z->y). Print out the string (i.e. all array elements) both before and after conversion on two separate lines. You can choose which one-third of the array each of the three methods will convert, as long as their combined work converts all m chars in the array. Can you imagine how you would change your program if four additional methods should be created to do the conversion, each of which converts one-fourth of the m chars? What about five methods? Six methods? Just submit the three-method version. A sample run can be seen later.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!