Question
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?
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 runningStep 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