博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
输入、方法的运用
阅读量:4631 次
发布时间:2019-06-09

本文共 1325 字,大约阅读时间需要 4 分钟。

/

/猜数游戏,编写一个功能,完成猜数游戏,产生一个1~10之间的随机数//与输入的数对对比,返回结果 猜中和没猜中import java.util.Scanner;     //引入(输入)的util包Scannerpublic class HelloWorld {public static void main(String[] args) {System.out.println(c());//返回的值} public static String c() {System.out.println("请输入一个数:");Scanner a=new Scanner(System.in);double b=a.nextFloat();//输入的数据类型和输入值 bdouble d=10*Math.random();//Math.random(),0-1的随机数
if (d==b) { return"猜中"; } else { return"没猜中"; } } }//返回

 

//方法的应用//同一个变量名可以承载多个方法//但多个方法中的括号内变量类型必须不同或者长度不同,同一个方法类型可以相同public class Thougth {    public static void main(String[] args){        int sum = add(2, 3);//        add(3.14,2.13);//        add(3.1f,2.1f);    }        public static int add(int a,int b) {        System.out.println("int 求和");        int sum = a + b;        return sum;    }        public static int add(int a) {        return a;    }    public static int add(int a,float b) {                return 0;    }        public static int add(float b,int a) {                return 0;    }        public static float add(float a,float b) {        System.out.println("float 求和");        float sum = a + b;        return sum;    }    public static double add(double a,double b) {        System.out.println("double 求和");        double sum = a + b;        return sum;    }}

 

转载于:https://www.cnblogs.com/406070989senlin/p/10721819.html

你可能感兴趣的文章
购物车组件开发
查看>>
Python 列表生成器
查看>>
Linux Shell编程从初学到精通
查看>>
Linux and the Device Tree
查看>>
「luogu2414」[AH2017/HNOI2017]礼物
查看>>
C# 控件命名规范
查看>>
求数组中两个子数组最大和
查看>>
javascript实现下雪效果
查看>>
定时修改用户密码
查看>>
LOJ 3093 「BJOI2019」光线——数学+思路
查看>>
python3 发送邮件添加附件
查看>>
Sublime Text 3 使用备注
查看>>
Hadoop 停止Job
查看>>
几个重点问题回顾
查看>>
隐藏空的cell
查看>>
转: Centos安装gcc及g++
查看>>
转:安桌开发开源库的推荐1
查看>>
学习总结(Java)
查看>>
怎么修改tomcat端口
查看>>
设置border为虚线
查看>>