This topic contains a solution. Click here to go to the answer

Author Question: Analyze the following code:import java.util.Scanner;public class Test { public static void ... (Read 60 times)

oliviahorn72

  • Hero Member
  • *****
  • Posts: 579
Analyze the following code:

import java.util.Scanner;

public class Test {
public static void main(String[] args) {
int sum = 0;
for (int i = 0; i < 100000; i++) {
Scanner input = new Scanner(System.in);
sum += input.nextInt();
}
}
}

◦ The program does not compile because the Scanner input = new Scanner(System.in); statement is inside the loop.
◦ The program compiles, but does not run because there is not prompting message for entering the input.
◦ The program compiles, but does not run because the Scanner input = new Scanner(System.in); statement is inside the loop.
◦ The program compiles and runs, but it is not efficient and unnecessary to execute the Scanner input = new Scanner(System.in); statement inside the loop. You should move the statement before the loop.


Related Topics

Need homework help now?

Ask unlimited questions for free

Ask a Question
Marked as best answer by oliviahorn72 on May 6, 2020

yifu223

  • Sr. Member
  • ****
  • Posts: 302
Lorsum iprem. Lorsus sur ipci. Lorsem sur iprem. Lorsum sur ipdi, lorsem sur ipci. Lorsum sur iprium, valum sur ipci et, vala sur ipci. Lorsem sur ipci, lorsa sur iprem. Valus sur ipdi. Lorsus sur iprium nunc, valem sur iprium. Valem sur ipdi. Lorsa sur iprium. Lorsum sur iprium. Valem sur ipdi. Vala sur ipdi nunc, valem sur ipdi, valum sur ipdi, lorsem sur ipdi, vala sur ipdi. Valem sur iprem nunc, lorsa sur iprium. Valum sur ipdi et, lorsus sur ipci. Valem sur iprem. Valem sur ipci. Lorsa sur iprium. Lorsem sur ipci, valus sur iprem. Lorsem sur iprem nunc, valus sur iprium.
Answer Preview
Only 25% of students answer this correctly




oliviahorn72

  • Member
  • Posts: 579
Reply 2 on: May 6, 2020
Thanks for the timely response, appreciate it


okolip

  • Member
  • Posts: 362
Reply 3 on: Yesterday
Wow, this really help

 

Did you know?

This year, an estimated 1.4 million Americans will have a new or recurrent heart attack.

Did you know?

Anesthesia awareness is a potentially disturbing adverse effect wherein patients who have been paralyzed with muscle relaxants may awaken. They may be aware of their surroundings but unable to communicate or move. Neurologic monitoring equipment that helps to more closely check the patient's anesthesia stages is now available to avoid the occurrence of anesthesia awareness.

Did you know?

More than 2,500 barbiturates have been synthesized. At the height of their popularity, about 50 were marketed for human use.

Did you know?

Children with strabismus (crossed eyes) can be treated. They are not able to outgrow this condition on their own, but with help, it can be more easily corrected at a younger age. It is important for infants to have eye examinations as early as possible in their development and then another at age 2 years.

Did you know?

The National Institutes of Health have supported research into acupuncture. This has shown that acupuncture significantly reduced pain associated with osteoarthritis of the knee, when used as a complement to conventional therapies.

For a complete list of videos, visit our video library