/
/猜数游戏,编写一个功能,完成猜数游戏,产生一个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; }}