Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

https://repl.it/@IbrahimYurdan/ShimmeringLongPackages#Main.java CAN YOU GUYS EXPLAIN THIS CODE PLEASE? import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner kb = new Scanner(System.in);

https://repl.it/@IbrahimYurdan/ShimmeringLongPackages#Main.java

CAN YOU GUYS EXPLAIN THIS CODE PLEASE?

image text in transcribed

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

Scanner kb = new Scanner(System.in);

System.out.println("Please enter an equation: ");

String equation = kb.nextLine();

System.out.println(calc(equation));

}

public static String calc(String equation) {

String e = "";

for (int i = 0; i

if (Character.isWhitespace(equation.charAt(i)) == false) {

e += equation.charAt(i);

}

}

for (int i = e.length() - 1; i > 0; i--) {

if (e.charAt(i) == '+') {

double add = Double.parseDouble(calc(e.substring(0, i)))

+ Double.parseDouble(calc(e.substring(i + 1, e.length())));

return add + "";

} else if (e.charAt(i) == '-') {

double sub = Double.parseDouble(calc(e.substring(0, i)))

- Double.parseDouble(calc(e.substring(i + 1, e.length())));

return sub + "";

}

}

for (int i = e.length() - 1; i > 0; i--) {

if (e.charAt(i) == '*') {

double multi = Double.parseDouble(calc(e.substring(0, i)))

* Double.parseDouble(calc(e.substring(i + 1, e.length())));

return multi + "";

} else if (e.charAt(i) == '/') {

double divide = Double.parseDouble(calc(e.substring(0, i)))

/ Double.parseDouble(calc(e.substring(i + 1, e.length())));

return divide + "";

}

}

for (int i = e.length() - 1; i > 0; i--) {

if (e.charAt(i) == '^') {

double pow = Math.pow(Double.parseDouble(calc(e.substring(0, i))),

Double.parseDouble(calc(e.substring(i + 1, e.length()))));

return pow + "";

}

}

return equation;

}

1. User inputs 2. The solvelt() method a. Parameters b. The use of recursive calls C. How parameter variables are used to iterate values in the recursion. d. The return 3. A Demonstration of all features of the program running

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

Step: 3

blur-text-image

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 Fundamentals Design

Authors: Marion Donnie Dutton Don F. Seaman

14th Edition Globel Edition

1292107634, 978-1292107639

More Books

Students also viewed these Databases questions

Question

How are members held accountable for serving in the assigned roles?

Answered: 1 week ago