**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". } }
**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".
}
}
Step by step
Solved in 4 steps with 2 images
Thank you!!! Would you mind telling me briefly what was wrong with the original code?