Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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;}

}

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing

Authors: David M. Kroenke

12th Edition International Edition

1292023422, 978-1292023427

More Books

Students also viewed these Databases questions