
Write a function that reads a string of digits, possibly preceded by + or -, and converts this string to the integer value it represents. Be sure that your function checksthat the string is well formed, that is, that it represents a valid integer. (Hint: use the functions provided in
any help would be highly appreciate.
thanks in advance.

import java.util.*;
public class Driver {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
int num1=0;
int num2=0;
char operator=' ';
int result=0;
System.out.println("Enter expressions such as 17 + 3 or 3.14159 * 4.7");
System.out.println("Use any of the operators +, -, *, /.");
System.out.println();
while (true){
System.out.print("Enter Expression: ");
String str=input.nextLine();
String st[]=str.split(" ");
if((st[0].matches("((-|\\+)?[0-9]+(\\.[0-9]+)?)+"))&&((st[1].charAt(0)=='+')||(st[1].charAt(0)=='-')||(st[1].charAt(0)=='*')||(st[1].charAt(0)=='/'))&&(st[2].matches("((-|\\+)?[0-9]+(\\.[0-9]+)?)+"))){
num1=Integer.parseInt(st[0]);
operator = st[1].charAt(0);
num2=Integer.parseInt(st[2]);
switch (operator) {
case '+':
result = num1 + num2;
break;
case '-':
result = num1 - num2;
break;
case '*':
result = num1 * num2;
break;
case '/':
result = num1 / num2;
break;
default:
System.out.println("Unknown operator: " + operator);
}
System.out.println("Result is " + result);
}
else{
System.out.println("Invalid Expression!");
break;
}
}
}
}

i think here we are not handling Array dynamically, suppose if we given 200+100 , then its trowing array index out of range error,so could you pls help me in this...
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.