**Please help fix code, code is not running and not giving output* Question to be answered: Using the code in the image provided: Implement a method called summation which adds two integers and returns their sum. INPUT: The first line of input contains an integer a. The Second Line of input containes and integer b. OUTPUT: Print the result which is the sum of a and b.   CODE: import java.util.*; import java.io.*; import java.math.*; class Outcome {     /*      * Implement method/function with name 'summation' below.      * The function accepts following as parameters.      *  1. a is of type int.      *  2. b is of type int.      * return int.      */     public static void main(String[] args)   {   Scanner sc=new Scanner(System.in);   int a,b;   a=sc.nextInt(); // enter 1st integer   b=sc.nextInt(); // enter 2nd integer   int sum=summation(a,b);   // call function   System.out.println(sum);  // display message   }     public static int summation(int a,int b){         //Write your code here        int s=0;      s=a+b;         // compute sum       return s;        //return type "int".     } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

**Please help fix code, code is not running and not giving output*

Question to be answered: Using the code in the image provided:

Implement a method called summation which adds two integers and returns their sum.

INPUT:

The first line of input contains an integer a.

The Second Line of input containes and integer b.

OUTPUT:

Print the result which is the sum of a and b.

 

CODE:

import java.util.*;
import java.io.*;
import java.math.*;
class Outcome {

    /*
     * Implement method/function with name 'summation' below.
     * The function accepts following as parameters.
     *  1. a is of type int.
     *  2. b is of type int.
     * return int.
     */
    public static void main(String[] args) 
 {
  Scanner sc=new Scanner(System.in);
  int a,b;
  a=sc.nextInt(); // enter 1st integer
  b=sc.nextInt(); // enter 2nd integer
  int sum=summation(a,b);   // call function
  System.out.println(sum);  // display message 
 }
    public static int summation(int a,int b){
        //Write your code here
       int s=0;
     s=a+b;         // compute sum 
     return s;  
     //return type "int".
    }

}

 

## Java Programming Example: Summation Function

This example demonstrates how to implement a simple summation function in Java. The `summation` function takes two integer parameters and returns their sum. Below is the annotated code explaining each part in detail.

```java
import java.util.*;   // Importing the utility package
import java.io.*;    // Importing the input-output package
import java.math.*;  // Importing the math package

class Outcome {

    /*
     * Implement method/function with name 'summation' below.
     * The function accepts the following as parameters:
     * 1. a is of type int.
     * 2. b is of type int.
     * return int.
     */
    public static void main(String[] args) {
        // Creating a Scanner object to get user input
        Scanner sc = new Scanner(System.in);
        
        // Declaring integer variables a and b
        int a, b;

        // Asking for user input and storing it in variable a
        a = sc.nextInt(); // Enter 1st integer
        
        // Asking for user input and storing it in variable b
        b = sc.nextInt(); // Enter 2nd integer
        
        // Calling the summation function with a and b, and storing the result in sum
        int sum = summation(a, b); // Call function
        
        // Printing the result to the console
        System.out.println(sum);   // Display message

        // Closing the scanner
        sc.close();
    }

    // Definition of the summation function
    public static int summation(int a, int b) {
        // Write your code here
        
        // Variable to store the sum of a and b
        int s = 0;
        
        // Performing the summation
        s = a + b;  // Compute sum
        
        // Returning the sum
        return s;   // Return type "int"
    }
}
```

### Detailed Explanation:

1. **Imports:**
   - `java.util.*;`: This imports the Java utility package which includes the `Scanner` class used for input.
   - `java.io.*;`: This imports the Java Input/Output package but is not used in this code.
   - `java.math.*;`: This imports the Java Math package but is not used in this code.

2. **Class Definition:**
   - The `Outcome` class
Transcribed Image Text:## Java Programming Example: Summation Function This example demonstrates how to implement a simple summation function in Java. The `summation` function takes two integer parameters and returns their sum. Below is the annotated code explaining each part in detail. ```java import java.util.*; // Importing the utility package import java.io.*; // Importing the input-output package import java.math.*; // Importing the math package class Outcome { /* * Implement method/function with name 'summation' below. * The function accepts the following as parameters: * 1. a is of type int. * 2. b is of type int. * return int. */ public static void main(String[] args) { // Creating a Scanner object to get user input Scanner sc = new Scanner(System.in); // Declaring integer variables a and b int a, b; // Asking for user input and storing it in variable a a = sc.nextInt(); // Enter 1st integer // Asking for user input and storing it in variable b b = sc.nextInt(); // Enter 2nd integer // Calling the summation function with a and b, and storing the result in sum int sum = summation(a, b); // Call function // Printing the result to the console System.out.println(sum); // Display message // Closing the scanner sc.close(); } // Definition of the summation function public static int summation(int a, int b) { // Write your code here // Variable to store the sum of a and b int s = 0; // Performing the summation s = a + b; // Compute sum // Returning the sum return s; // Return type "int" } } ``` ### Detailed Explanation: 1. **Imports:** - `java.util.*;`: This imports the Java utility package which includes the `Scanner` class used for input. - `java.io.*;`: This imports the Java Input/Output package but is not used in this code. - `java.math.*;`: This imports the Java Math package but is not used in this code. 2. **Class Definition:** - The `Outcome` class
Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

Thank you!!! Would you mind telling me briefly what was wrong with the original code?

 

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education