What are the errors of this code ? 1 import java.io.*; 2 3 4 6 7 8
Fantastic news! We've Found the answer you've been seeking!
Question:
What are the errors of this code ?
Transcribed Image Text:
1 import java.io.*; 2 3 4 6 7 8 9 import java.util.*; // Declare class public class Sum{ public static void main (String [] args) throws FileNotFoundException{ } Scanner input = new Scanner (System.in); string numbers = input.nextLine(); boolean result = negativeSum (numbers); //System.out.println(result); //STATIC METHOD negativeSum BEGINS HERE 10 11 12 13- 14 15 16 18 19 // 20-> 21- public static boolean negativeSum(Scanner numbers) { int sum e; // NUMBER COUNT int count e; // SUMMATION OF NUMBERS boolean neg = false; // LOOP THROUGH ARRAY OF NUMBERS string[] nums = numbers.split(" "); PARSE STRING INTO AN INTEGER for (int i = 0; i < nums.length; i++) { try{ 22 // IF THE STRING IS AN INTEGER, ADD IT TO SUM int num = Integer.parseInt(nums[i]); 23 count++; sum = sum + num; if (sum <0) { System.out.println(sum + " after." +count + 24 25 26 28 neg = true; 29 break; 30 } 31 }catch 327 33 // IF NUMBER IS NOT AN INTEGER, SKIP IT 34 (NumberFormatException e) { 35 continue; } } 36 37 // CALCULATE AND PRINT PERCENTAGE OF EVEN NUMBER if(Ineg){ 38 39-> 40 41 } 42 43 44 System.out.println("No negative sum"); return neg; } Execute Mode, Version, Inputs & Arguments For Multip steps "); 1 import java.io.*; 2 3 4 6 7 8 9 import java.util.*; // Declare class public class Sum{ public static void main (String [] args) throws FileNotFoundException{ } Scanner input = new Scanner (System.in); string numbers = input.nextLine(); boolean result = negativeSum (numbers); //System.out.println(result); //STATIC METHOD negativeSum BEGINS HERE 10 11 12 13- 14 15 16 18 19 // 20-> 21- public static boolean negativeSum(Scanner numbers) { int sum e; // NUMBER COUNT int count e; // SUMMATION OF NUMBERS boolean neg = false; // LOOP THROUGH ARRAY OF NUMBERS string[] nums = numbers.split(" "); PARSE STRING INTO AN INTEGER for (int i = 0; i < nums.length; i++) { try{ 22 // IF THE STRING IS AN INTEGER, ADD IT TO SUM int num = Integer.parseInt(nums[i]); 23 count++; sum = sum + num; if (sum <0) { System.out.println(sum + " after." +count + 24 25 26 28 neg = true; 29 break; 30 } 31 }catch 327 33 // IF NUMBER IS NOT AN INTEGER, SKIP IT 34 (NumberFormatException e) { 35 continue; } } 36 37 // CALCULATE AND PRINT PERCENTAGE OF EVEN NUMBER if(Ineg){ 38 39-> 40 41 } 42 43 44 System.out.println("No negative sum"); return neg; } Execute Mode, Version, Inputs & Arguments For Multip steps ");
Expert Answer:
Posted Date:
Students also viewed these programming questions
-
Discuss which organizational structure (i.e. functional, product-market divisional, matrix) you would recommend Guelph General Hospital implement, assuming the hospital moves forward with the...
-
Sasha Company allocates the estimated $199,400 of its accounting department costs to its production and sales departments since the accounting department supports the other two departments...
-
Some Practice Problems for the C++ Exam and Solutions for the Problems The problems below are not intended to teach you how to program in C++. You should not attempt them until you believe you have...
-
Use any method to determine if the series converges or diverges. Give reasons for your answer. n10 10" n=1
-
Explain in detail what a normal probability plot is and how it is used to assess the normality of a variable.
-
Pettit Printing Company has a total market value of $100 million, consisting of 1 million shares selling for $50 per share and $50 million of 10 percent perpetual bonds now selling at par. The...
-
Classify each of the following items as prevention, appraisal, internal failure, and external failure costs: a. Product warranty costs b. Vendor survey and review c. Design of product test equipment...
-
Southern Outpost Co. has several contingent liabilities at December 31, 2011. The auditor obtained the following brief description of each liability: (a) In May 2010, Southern Outpost became involved...
-
Leslie has been with her employer for 15 consecutive weeks and is a reservist with the Canadian Forces. Leslie intends to take a reservist leave. Pursuant to Alberta's Employment Standards Code, how...
-
Q2. (20) Skim milk (S) is produced by removing of some of the milk fat (F) from the whole milk (M). This skim milk contains 90.5% water, 3.5% protein, 5.1% carbohydrates, 0.8% ash, and 0.1% fat....
-
Thomlin Company forecasts that total factory overhead for the current year will be $15,000,000 with 300,000 total machine hours. Year to date, the actual factory overhead is $16,000,000 and the...
-
Phillips Company bought 40 percent ownership in Jones Bag Company on January 1, 20X1, at underlying book value. During the period of January 1, 20X1, through December 31, 20X3, the market value of...
-
Explain the thematic significance of existentialism in existentialist literature. How do these works interrogate concepts of meaning, freedom, and human existence ?
-
Marcy, age 1 2 , earned $ 4 0 0 from babysitting during 2 0 2 2 . Her parents claim her as a dependent. She also had interest and dividends of $ 2 , 8 0 0 during the year. She did not itemize...
-
Schonhardt Corporation's relevant range of activity is 4,100 units to 9,500 units. When it produces and sells 6,800 units, its average costs per unit are as follows: Average Cost per Unit Direct...
-
A buyer is interested in a group of tweed jackets costing $35 each. If the required markup is 53.6%, what would be the minimum retail price for each jacket? If the buyer had previously bought these...
-
Use critical values to test the null hypothesis H0: 1 2 = 20 versus the alternative hypothesis H0: 1 2 20 by setting a equal to .10, .05, .01, and .001. How much evidence is there that the...
-
The budget director of Amys Florist has prepared the following sales budget. The company had \($200,000\) in accounts receivable on July 1. Amys Florist normally collects 100 percent of accounts...
-
Stenton Corporation, which has three divisions, is preparing its sales budget. Each division expects a different growth rate because economic conditions vary in different regions of the country. The...
-
Write a brief memo describing the sales pattern that you would expect Kandy to experience during the year. In which months will sales likely be high? In which months will sales likely be low? Explain...
Study smarter with the SolutionInn App