Question
Help with java Please import java.util.*; public class Recursion{ public static void main(String args[]){ Scanner input = new Scanner(System.in); String exp = input.nextLine(); System.out.println(solver(exp.split( )));
Help with java Please
import java.util.*;
public class Recursion{
public static void main(String args[]){
Scanner input = new Scanner(System.in);
String exp = input.nextLine();
System.out.println(solver(exp.split(" ")));
}
public static double solver(String[] expression){
double result = 0;
if(expression.length == 3){result = add(Double.parseDouble(expression[0]),Double.parseDouble(expression[2]));}
else if(expression.length == 5){result = add(Double.parseDouble(expression[0]),Double.parseDouble(expression[2]),Double.parseDouble(expression[4]));}
else if(expression.length == 7){result = add(Double.parseDouble(expression[0]),Double.parseDouble(expression[2]),Double.parseDouble(expression[4]),Double.parseDouble(expression[6]));}
else if(expression.length == 9){result = add(Double.parseDouble(expression[0]),Double.parseDouble(expression[2]),Double.parseDouble(expression[4]),Double.parseDouble(expression[6]),Double.parseDouble(expression[8]));}
else if(expression.length == 11){result = add(Double.parseDouble(expression[0]),Double.parseDouble(expression[2]),Double.parseDouble(expression[4]),Double.parseDouble(expression[6]),Double.parseDouble(expression[8]),Double.parseDouble(expression[10]));}
return result;
}
public static double add (double a, double b){return a+b;}
public static double add(double a, double b, double c){return a+b+c;}
public static double add(double a, double b, double c, double d){return a+b+c+d;}
public static double add(double a, double b, double c, double d, double e){return a+b+c+d+e;}
public static double add(double a, double b, double c, double d, double e, double f){return a+b+c+d+e+f;}
}
Output 7. 3+ COME AND RUN Sumit your code by pressing the button Net
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started