String转换为Int或者long
怎么将Sring类型的123转换为int或者long类型的123?
----------------解决方案--------------------------------------------------------
long l = Long.parseLong("123");
int i = Integer.parseInt("123");
----------------解决方案--------------------------------------------------------
int i = Integer.parseInt("123");
----------------解决方案--------------------------------------------------------
int i = Integer.parseInt("123");
----------------解决方案--------------------------------------------------------
import javax.swing.JOptionPane;
public class book2_7 {
public static void main(String [] args){
String amountString = JOptionPane.showInputDialog(
"Enter an amount in double,for example 123.15");
double amount = Double.parseDouble(amountString);
int remainingAmount=(int)(amount*100);
int numberOfOneDollars = remainingAmount/100;
remainingAmount=remainingAmount%100;
int numberOfQuarters=remainingAmount/25;
remainingAmount=remainingAmount%25;
int numberOfDimes= remainingAmount/10;
remainingAmount=remainingAmount%10;
int numberOfNickels=remainingAmount/5;
remainingAmount=remainingAmount%5;
int numberOfPannies=remainingAmount;
String output="Your amount "+amount+" consists of \n"
+numberOfOneDollars+" dollars\n"+numberOfQuarters+
" quarters\n"+numberOfDimes+" dimes\n"+numberOfNickels+
" nickels\n"+numberOfPannies+" pannies\n";
JOptionPane.showMessageDialog(null,output);
}
}
----------------解决方案--------------------------------------------------------