# string to double

So I have an assignment where we have to convert strings into double.I have to modify the method parseDouble() to fully implement the method to imitate the Double.parseDouble() method of Java. In other words, parseDouble() method takes a String as input and converts it into a double when possible and returns it. If the string cannot be converted into a positive double, it returns -1.You will also modify the main method to ask the user to input a positive double in a JoptionPane, then use your parseDouble method (not Java's built-in parseDouble method) to convert it to a double and return twice the value of the input, or a message that the input is not a valid positive number.

and this is my code: I just can't figure out if I did it right or not

```import javax.swing.JOptionPane;

public class Parsing {
public static int parseInt(String value) {
int x = 0;
int digit = 0;
for (int i=0; i<value.length(); i++) {
switch (value.charAt(i)) {
case '0':
digit = 0;
break;
case '1':
digit = 1;
break;
case '2':
digit = 2;
break;
case '3':
digit = 3;
break;
case '4':
digit = 4;
break;
case '5':
digit = 5;
break;
case '6':
digit = 6;
break;
case '7':
digit = 7;
break;
case '8':
digit = 8;
break;
case '9':
digit = 9;
break;
default:
return -1;
}
x = x*10 + digit;
}
return x;
}

public static double parseDouble(String value) {
double x = 0;
int digit = 0;
boolean beforeDecimal = true;
int factor = 0;
for (int i=0; i<value.length(); i++) {
switch (value.charAt(i)) {
case '0':
digit = 0;
break;
case '1':
digit = 1;
break;
case '2':
digit = 2;
break;
case '3':
digit = 3;
break;
case '4':
digit = 4;
break;
case '5':
digit = 5;
break;
case '6':
digit = 6;
break;
case '7':
digit = 7;
break;
case '8':
digit = 8;
break;
case '9':
digit = 9;
break;
case '.':
beforeDecimal = false;
break;
default:
return -1;
}
//change the code below
if (beforeDecimal) {
x = x*10 + digit;
}
//else

}
return x;
}
public static void main(String[] args) {
//declare variables
String input;
int x;
// Ask user for an integer
input = JOptionPane.showInputDialog(null,
x = parseInt(input);
JOptionPane.showMessageDialog(null,
"Twice of that number is "+ 2*x);

}

}
```

string to double
string to double   So I have an assignment where we have to convert..., parseDouble() method takes a String as input and converts it into a double when possible and returns it. If the string cannot be converted into a positive double
converting string to double in java
converting string to double in java  Please post an example to converting string to double in java. Thanks!   Convert String to Double Tutorial
how to convert string to double in java
how to convert string to double in java  Hi, I have String variable with double value in it. how to convert string to double in java? Thanks  ... to convert a String into double. Here is full example code: package net.roseindia
how to convert string to double in java
how to convert string to double in java  Hi, I have String variable with double value in it. how to convert string to double in java? Thanks  ... to convert a String into double. Here is full example code: package net.roseindia
how to convert string to double in java
how to convert string to double in java  Hi, I have String variable with double value in it. how to convert string to double in java? Thanks  ... to convert a String into double. Here is full example code: package net.roseindia
how to convert string to double in java
how to convert string to double in java  Hi, I have String variable with double value in it. how to convert string to double in java? Thanks  ... to convert a String into double. Here is full example code: package net.roseindia
Convert String To Double
Convert String To Double      ... numeric type string value:" message and it converts into a double... StringToDouble Enter string value: 23 double d = 23.0
Conversion from String to double
Conversion from String to double: In this tutorial we will learn how to convert a string type data to double type data. Description: This program will take a String value from mystring variable. The line double mydouble
Conversion from double to String
Conversion from double to String: In this tutorial we will learn how to convert a double type value to String type value. Description: This program will take a double value from console and provide the conversion to String type
Convert Double To String
Convert Double To String      ...; This section learns you the conversion of double into string. The following program... a variable of double type and convert it into the string form by using toString
Making XY line chart with string and double axis
Making XY line chart with string and double axis  Good evening... into the dataset. The horizontal axis are going to be represented by a string (showing day and time) and the vertical indicates temperature (double) Now my question is what
Double To Int Without TypeCasting
void main(String[] args) { double d=25.5; int num=new Double(d).intValue(); System.out.println(num...Double To Int Without TypeCasting  How to convert Double to Int
NSString to double
NSString to double  Hi, I want to convert NSString value into double. Please give me good code example for this conversion. Thanks   Hi... scannerWithString:@"1.309"]; double dblLat; [strLat scanDouble:&
NSString to double
NSString to double  Hi, I want to convert NSString value into double. Please give me good code example for this conversion. Thanks
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
string
string  String helloString = new String(helloArray); System.out.println(helloString); i am unable to understand this. could u plz explain
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
String
characters in string?   import java.util.*; class RemoveDuplicateCharatcersFromString { public static String removeDuplicates(String s... < s.length(); i++) { String st = s.substring(i, i + 1
single quotes or double quotes
single quotes or double quotes  Would you initialize your strings with single quotes or double quotes?   Hi friends, Both are good but I would prefer & recommend that we go for initializing string with single
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
string
string  a java program to input a string and display the string...*; import java.io.*; public class FirstLetter{ public static String capitalizeFirstLetter( String str ) { final StringTokenizer st = new StringTokenizer( str
string
string   just i want to a program in a short form to the given string in buffered reader for example input string: Suresh Chandra Gupta output: S. C...; public class StringTest { public static void main(String [] args
string
string  java prgm to find total occurence of a given string pattern in a sentence
string
string  java prgm to find total occurence of a given string pattern in a sentence
String
String  write a program using string it should replace 'c'char to integer number as 1 in whole source
String
String  How to Convert sunnapu gopal to Sunnapu Gopal in java using String
String
String  how to print in between numbers if the question "String s = "1,2,3,4,5,6,8,-25"" out must be 1 2,3,4,5,6,7,8,9,10,upto25
string
and also displaying that contain word? Like I want to find "a" in the string... and a character. It then count the occurrence of that character in the string and display... String_Example { public static void main(String[] args
string
string  program for String reverse and replace in c,c++,java e.g.Input:10,20,hello output:hello;20;10   Hi Friend, Try the following java...(String[] args) { String array[]=new String[5]; Scanner input
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