美文网首页
1.3.1 浮点数

1.3.1 浮点数

作者: harukou_ou | 来源:发表于2019-02-02 17:55 被阅读5次

    体会浮点数的用处

    package test;
    
    import java.util.Scanner;
    
    public class Test1java {
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            int foot;
            int inch;
            Scanner in = new Scanner(System.in);
            
            foot = in.nextInt();
            inch = in.nextInt();
            // 这里的12.0保证了计算结果
            System.out.println((foot+inch/12.0)*0.3048);
        }
    
    }
    
    package test;
    
    import java.util.Scanner;
    
    public class Test1java {
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            double foot;
            double inch;
            Scanner in = new Scanner(System.in);
            
            foot = in.nextInt();
            inch = in.nextInt();
            
            System.out.println((foot+inch/12)*0.3048);
        }
    
    }
    
    
    package test;
    
    import java.util.Scanner;
    
    public class Test1java {
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            double foot;
            double inch;
            Scanner in = new Scanner(System.in);
            
            foot = in.nextDouble();
            inch = in.nextDouble();
            
            System.out.println((foot+inch/12)*0.3048);
        }
    
    }
    

    比较上述代码异同

    相关文章

      网友评论

          本文标题:1.3.1 浮点数

          本文链接:https://www.haomeiwen.com/subject/deassqtx.html