代码练习--数据类型

it2026-04-25  4

package cn.neusoft.practice; import java.util.Scanner; public class DateType {     public static void main(String[] args){         /**          * 第一次课堂练习 P26(1)          * 定义变量名a,b,c,d,e,数据类型分别是 int,Boolean,float,double,char,赋值并且输出          *           *          int a = 10;         boolean b = true;         float c = 3.1456f;         double d = 3.1415926;         char e = 'a';         System.out.println("a = "+ a);         System.out.println(b);         System.out.println(c);         System.out.println(d);         System.out.println(e);         //         int f = (int)(Math.random() * 100) ;         System.out.println(f);         */    

          /**  * P27        如何产生随机的整数范围在10--90之间,包含10和90  *   *              int a = (int)(10 + Math.random() * 10 + 1);         System.out.println(a);     */         

/**  * 课堂练习  *1、输入一个圆柱体的高和半径,求体积   *底面积(πr平方)*高    *      

    Scanner sc = new Scanner(System.in);     System.out.print("请输入圆柱体的高:");     double high  = sc.nextDouble();          System.out.print("请输入圆柱体的半径:");     double r  = sc.nextDouble();          double volume = 3.14 * r * r * high;     System.out.print("圆柱体的体积:");     System.out.println(String.format("%.2f",volume));         */

     /**  *2、从键盘输入一个摄氏温度C,计算华氏温度F并且输出(F = (9/5)* C + 32 )  *  **/              Scanner sc = new Scanner(System.in);         System.out.print("请输入摄氏温度:");         double x = sc.nextDouble();                  double huashi = (9 / 5 ) * x + 32;         System.out.println("华氏温度为:"+huashi+"华氏度");

         } }

}  

最新回复(0)