COMPLETE QUESTION
I. public class Test {
public static void main(String[] args){
System.out.println("Welcome to Java!");
}
}
II. public class Test { public static void main(String[] args) {System.out.println("Welcome to Java!");}}
Answer:
Both codes will compile and run and display Welcome to Java, but the code in II has a better style than I
Explanation:
When written codes, paying attention to proper coding styles and efficient memory management enables us to create programs that are highly efficient, coding styles refer to proper indentions and avoiding too lenghty lines of code (as is in code I), adding approprite comments etc.
Answer:
a) "Quit"
c) "Q only
Explanation:
Given
<em>String s = "Go"; </em>
<em>while ((!s.equals("q"))&& (!s.equals(""))) {</em>
<em>System.out.println("In loop"); </em>
<em>s = scnr.next();</em>
<em>}</em>
<em />
Required
What input causes another execution
Analyzing the while condition
<em>while ((!s.equals("q"))&& (!s.equals(""))) </em>
<em />
This can be split into:
<em>!s.equals("q")) && (!s.equals(""))</em>
<em />
Meaning
When s is not equal to "q" and when s is not an empty string
<em />
In other words,
the loop will be executed when user input is not "q" and user input is not empty.
So, from the list of given options: The loop both will be executed when:
a) Input is "Quit"
c) Input is Q only
<em>Input of q will terminate the loop, hence b and d are incorrect</em>
<em />
Answer:
The following fix were made to the program
- Change void main() to int main(), then set a return value at the end of the main function; e.g. return 0
- Remove system("pause"); It's not needed
- For each of the array, change their lengths to 5 i.e. int votes[5]; string name[5]; and float percent[5];
- Lastly, calculate the percentage using: percent[i]=((votes[i]*100.0/total))
Explanation:
(1) void main implies that the main function will not return any value. So, you change it to int main() and then set the return value
(2) There is no need to pause the program, so system.("pause") is not necessary.
(3) The question says there are 5 candidates. So, we set the arrays to accommodate inputs for 5 values
(4) percent array is declared as float; 100.0 will ensure that it calculates the percentage as a float value.
<em>See attachment for updated code</em>
Answer:
B and C
Explanation:
Possible solution to solving "BOOTMGR is missing" error in Windows Vista is to use the Windows Recovery Environment.
Another option is to run "bootrec/fixboot" command from the comman prompt and the command prompt is also accessible from the windows recovery environment.