我是非常菜鸟integer.parseInt说取整型数的,那么浮点数应该用什么。

解决方案 »

  1.   

    class Integer:
    static int parseInt(String s) 
              Parses the string argument as a signed decimal integer.this method returns an int value,for your request of float,you can use Float.parseFloat(String s) :static float parseFloat(String s) 
              Returns a new float initialized to the value represented by the specified String, as performed by the valueOf method of class Float.
      

  2.   

    如果我输入浮点数,怎么才能分别输出整数部分和小数部分。import java.io.*;public class H39
    {
    public static void main(String args[])
    {

    float f = 0.0F;
    String s;

    try
    {
    System.out.print("enter:");
    BufferedReader br =
    new BufferedReader(new InputStreamReader(System.in));
    s = br.readLine();
    f = Float.parseFloat(s);
    }catch(IOException e){
    }
    System.out.println("output:" + f);
    System.out.println("output:" + i);
    }
    }现在这样是输出浮点
      

  3.   

    建议去下载个J2SE的API 要学会查,自己查。。
    建议~~:)
      

  4.   

    import java.io.*;
    public class ch3_e3_9
    {
    public static void main(String args[])
    {
    String s;
    double d;
    int i;
    boolean b=false;
    do{
    try{
    System.out.println("请输入一个浮点数:");
    BufferedReader br=
    new BufferedReader(new InputStreamReader(System.in));
     s=br.readLine();
     i=s.indexOf(".");
     d=Double.parseDouble(s);
     System.out.println(d+"整数部分为:"+(long)d);
      if(i == -1) 
      System.out.println(d+"小数部分为:0.0");
      else
      System.out.println(d+"小数部分为:"+Double.parseDouble(s.substring(i+1,s.length())));
      b=false;
                             }                         catch(IOException ioe)                         {                                    b=false;                         }     
                      }while(b);
    }
    }写出来了,J2SE的API 下来,但是有点摸不着头脑,才开始学java,都大3才开,疯了
      

  5.   

    向这种问题就不要老是发帖子了,多看看Java 2 SDK就可以了,要培养自己的自学的能力。