Write a fragment of code that will change the integer value stored in x as follows. If x is even, divide x by 2. If x is odd, multiply x by 3 and subtract 1.

What will be an ideal response?


```
if(x % 2 == 1)
x = 3*x - 1;
else
x = x/2;
```
if(x % 2 == 1)
x = 3*x - 1;
else
x = x/2;
if(x % 2 == 1)
x = 3*x - 1;
else
x = x/2;

This code is in Fragments.java.

Computer Science & Information Technology

You might also like to view...

Answer the following statements true (T) or false (F)

1) The primary purpose of a set is to determine if a particular element is a member of the set. 2) Set is not the only collection type that supports testing for membership. 3) Sets and maps can be implemented using either binary trees or by using a hashing function. 4) A hashing function is a function that maps elements of a set or a map to other elements that are in the set or the map. 5) When implementing a map class or a set class using a tree data structure, a heap is used for the tree.

Computer Science & Information Technology

Match each item with a statement below.

A. a protocol in IPv6 that permits nodes and routers on a local link to keep one another updated about any recent change in their network connectivity or status B. a method for checking the IPv6 address that a node wishes to use by sending a Neighbor Advertisement message to see if it is already in use by some other node C. messages used to find (or verify) the link-layer address for a local node, to see if that node is still available, or to check that an address is not in use by another node D. a message sent out by a router which contains its own link-layer address, the network prefix of the local subnet, the MTU for the local link, suggested hop limit values, and other parameters useful for nodes on the local link E. messages sent by nodes that include their IPv6 and link-layer addresses to maintain information about local addresses and on-link status F. a reserved address used as a source address if a node does not have an assigned IPv6 address G. a message sent out by a router to inform a sending node that there is a better first-hop router to access a destination node that is off-link H. a message sent out by a node to ask routers connected to a local link to identify themselves by immediately sending a Router Advertisement message rather than waiting for the next scheduled advertisement to appear I. a multicast address with link-local scope, which helps reduce the number of multicast groups to which nodes must subscribe in order to make themselves available for solicitation by other nodes on their local links

Computer Science & Information Technology

Windows Task Manager is an application that will be displayed in the Task Manager as taskmgr.exe

Indicate whether the statement is true or false

Computer Science & Information Technology

To use different page number formats within the same document, format the preliminary pages and the remainder of the report as separate ____.

A. documents B. pages C. sections D. files

Computer Science & Information Technology