Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

in this program, the only way it will work if the equaiton is spaced out. TO rec

ID: 3591080 • Letter: I

Question

in this program, the only way it will work if the equaiton is spaced out. TO recieve extra credit. i need to alter the program to where it doesnt have to have spaces in the users equation

Scanner kbd - new Scanner (System.in); System.out.println( "Equation: ");//declaring three seperate variables int firstInt-kbd.nextInt(); String secondPlace-kbd.next); int secondInt-kbd.nextInt(); DecimalFormat numberFormat - new DecimalFormat ("#.ee"); if (secondInt!-e)(//starting off by seeing if user is try to divide by zero switch (secondPlace)//else start calculatons case "+" System.out.print (firstInt + " + " + secondInt-. ");//equation for additon System.out.println(firstInt+secondInt); break

Explanation / Answer

import java.util.Scanner;
public class HelloWorld{

public static void main(String []args){
Scanner kbd = new Scanner(System.in);
System.out.println("Equation :");
String str = kbd.nextLine();
char secondPlace;
int firstInt=0,secondInt=0;
for(int i=0;i<str.length();i++)
{
if(!(Character.isDigit(str.charAt(i))))
{
  
firstInt=Integer.parseInt(str.substring(x,i));
secondInt=Integer.parseInt(str.substring(i+1,str.length()));

secondPlace=str.charAt(i);
  
break;
}

}


}
}

Note: This method will help you where space is not required in the user equation.