# Write a function that reads a string of digits, possibly preceded by + or -, and converts this string to the integer value it represents.

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 and ). Also, write a driver programs to test the function.

any help would be highly appreciate. June 16, 2011 at 4:22 PM

```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.matches("((-|\\+)?[0-9]+(\\.[0-9]+)?)+"))&&((st.charAt(0)=='+')||(st.charAt(0)=='-')||(st.charAt(0)=='*')||(st.charAt(0)=='/'))&&(st.matches("((-|\\+)?[0-9]+(\\.[0-9]+)?)+"))){
num1=Integer.parseInt(st);
operator = st.charAt(0);
num2=Integer.parseInt(st);
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;
}
}

}
}
``` June 16, 2011 at 5:18 PM

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...

Write a function that reads a string of digits, possibly preceded by + or -, and converts this string to the integer value it represents.
Write a function that reads a string of digits, possibly preceded by + or -, and converts this string to the integer value it represents.  Write a function that reads a string of digits, possibly preceded by + or -, and converts
Java get Int from String
(st) converts the string into the integer. Here is the code... Java get Int from String       In this section, you will study how to obtain the integer value
integer to string
integer to string  i have to develop a program which convert integer into character from 1 to 10,000 if we input 1 then it give output 'one' n so on till 'ten thousand' kindly give me the codes plzplz sir........   Have
how to write a function to print for finding the longest palindrome in the given string
how to write a function to print for finding the longest palindrome in the given string  how to write a function to print for finding the longest palindrome in the given string
javascript integer to string conversion
javascript integer to string conversion  How to Javascript Integer to String Conversion   <script type="text/javascript"> /** * print out the value and the type of the variable passed
Convert a String into an Integer Data
Convert a String into an Integer Data  ... a string type data into an integer type. The java.lang package provides the functionality to convert the string type data into an integer type data. Code
Convert an Integer into a String
converts an integer value into a String.  Here is the code of this program... an integer number at  the console and it converts it into a string format... Convert an Integer into a String
find the given input is integer or string
the given input value is integer or no.If the given value is integer display "Value is integer" otherwise "Value is not a integer"?   class...){ System.out.println("Value is integer!"); } else
Converting a String to Integer in Java
Converting a String to Integer in Java In this video tutorial I will show you how to convert a String value to Integer in Java? The easiest way to convert.... There are two methods of converting the String into integer value. One method
java string replace all non digits
except the digits. How to replace all non digits in a string with some character... in combination with the replaceAll function of String. Following regular...java string replace all non digits  Hi, I am doing some processing
Conversion of String to Integer
Conversion of String to Integer  public class Test { public static void main(String[] args) { int countA = 0; int countB = 0...'; chr++) { (int) String "count"+chr = 0
Write String in Word document
Write String in Word document  How to read and write strings in word document
change value of mutable string
change value of mutable string  How to change value of mutable string
String Function Program
String Function Program  The string function program is just an application of the string manipulation functions in JAVA. The program is designed to count the number of one-letter word, two-letter word, and three-letter words
write a program to create an arraylist with string(add,remove) operation.and value should be enter through keyboard.
write a program to create an arraylist with string(add,remove) operation.and value should be enter through keyboard.  write a program to create an arraylist with string(add,remove) operation.and value should be enter through
write a program to create an arraylist with string(add,remove) operation.and value should be enter through keyboard.
write a program to create an arraylist with string(add,remove) operation.and value should be enter through keyboard.  write a program to create an arraylist with string(add,remove) operation.and value should be enter through
write a program to create an vector with string(add,remove) operation.and value should be enter through keyboard.
write a program to create an vector with string(add,remove) operation.and value should be enter through keyboard.  write a program to create an vector with string(add,remove) operation.and value should be enter through keyboard
Convert a String into an Integer Data
Convert a String into an Integer Data In this section you will learn to convert a string type of data to integer type data. Converting string to integer and integer to string is a basic task in java programming language because
String
String  write a program using string it should replace 'c'char to integer number as 1 in whole source
String doubt replace function
String doubt replace function  What is the output and why of below : String s1 = "Hello"; if(s1.replace('H','H')== "Hello") System.out.println("yes"); else System.out.println("No"); if(s1.replace("H", "H")== "Hello
String
String  write down the code of remove any character from a given string without using any string function   please give me the code of remove any given character from a given string without using function
i want display integer number in a string of statement
i want display integer number in a string of statement  i want display integer number in a string of statement
C String to Int
>, to convert the string value of digits ("100") into int value...; In this section, you will learn how to convert a string represented value into an integer represented value in C. You can see in the given example that we
Java integer to string
Java integer to string       Many times we need to convert a number to a string to be able to operate on the value in its string form. Converting numeric values to Strings with Java
string
string  a java program using string function to input any string... ArrangeStringAlphabetically { public static void main(String[] args) { Scanner input=new Scanner(System.in); System.out.print("Enter string
in string how will write the return statement..........?
in string how will write the return statement..........?  import...; public static void main(String args[]){ int i=Integer.parseInt(args[0... 256"); } else{ binary(i); } } public static String binary(int i
I am writing a program which converts a string to a timestamp and add days to it
I am writing a program which converts a string to a timestamp and add days to it  java.sql.Timestamp ts2 = java.sql.Timestamp.valueOf("2012-01-11 12:34:39"); long l=ts2.getTime() +(100060602424);//add 24 days Date d=new Date(l
string
string  a java program using string function that computes your initials from your full name and display them   Please visit the following links: http://www.roseindia.net/tutorial/java/core/printInitials.html http
Error in checking null value in string
Error in checking null value in string  Error in checking null value in string Hi am getting Exception : java.lang.NullPointerException in the following code: String registerno=null; registerno=request.getParameter("registerno
STRING.....
STRING.....  plzz sent me d code for counting vowels in a string... gui programme
string
string   difference detween "public static void main (String[] args) " and "public static void main (String args[])" in java but it executes both... "String args[]" can mean a "string array called args which is an array