import java.util.Random;
import java.util.Scanner;
public class Test {
//求最大值方法的重载 : 在同一类中定义多个方法:要求不仅可以求两个整数max,还可以求三个小数的最大值
public static int maxInt(int a,int b) {
return a > b ? a : b;
}
public static double maxDouble(double a,double b,double c) {
double m = Math.max(a,b);
return m > c ? m : c;
}
public static void main(String[] args) {
System.out.println(maxInt(2,9));
System.out.println(maxDouble(2.0,3.0,6.0));
}
//求和的重载: 在同一类中,分别定义两个整数和的方法,求三个小数之和的方法,并执行,求结果
public static int addInt(int a,int b) {
return a + b;
}
public static double addDouble(double a,double b,double c) {
return a + b + c;
}
public static void main27(String[] args) {
int fun1 = addInt(1,5);
double fun2 = addDouble(1.0,5.0,3.0);
System.out.println(fun1);
System.out.println(fun2);
}
//求斐波那契数列的第n项(迭代实现)
public static void fit(){
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int a = 1;
int b = 1;
int c = 0;
for (int i = 3; i <= n; i++) {
c = a + b;
a = b;
b = c;
}
if(n <= 2) {
c = 1;
}
System.out.println(c);
}
public static void main26(String[] args) {
fit();
}
//使用函数的最大值,创建方法求两个数的最大值max2,随后在写一个求三位数的最大值max3
//要求: 在max3这个函数中调用max2函数,来实现3个数的最大值
public static int max4(int a,int b) {
return a > b ? a:b;
}
public static int max5(int a,int b,int c) {
int j = max2(a,b);
return j > c ? j:c;
}
public static void main25(String[] args) {
int i = max5(100,2,99);
System.out.println(i);
}
public static int max2(int a,int b) {
if(a > b) {
return a;
} else {
return b;
}
}
public static int max3(int a,int b,int c) {
int j = max2(a,b);
if( j > c) {
return j;
} else {
return c;
}
}
public static void main24(String[] args) {
int i = max3(100,2,99);
System.out.println(i);
}
//模拟登陆 编写代码模拟密码输入的场景,最多能输入三次密码,密码正确,提示“登陆成功”,密码错误,可重新输入,
//最多输入三次,三次均错,则提示退出程序。
public static void login () {
Scanner scanner = new Scanner(System.in);
int count = 3;
while(count != 0) {
String passWard = scanner.nextLine();
if(passWard.equals("123456")) {
System.out.println("密码输入正确,登陆成功!");
} else {
count--;
System.out.println("密码输入失败!");
System.out.println("你还有" + count + "次机会");
if(count == 0) {
System.out.println("退出程序!");
}
}
}
}
public static void main23(String[] args) {
login();
}
//猜数字游戏 :系统自动生成1-100的数字,然后用户输入一个猜测的数字,如果输入的数字比随机数小,提示“低了”如果......
public static void main22(String[] args) {
Scanner scanner = new Scanner(System.in);
Random random = new Random();
int ranNum = random.nextInt(100);//[1,100)
//System.out.println(random);
while(true) {
int n = scanner.nextInt();
if(n < ranNum) {
System.out.println("猜小了");
}
if(n > ranNum) {
System.out.println("猜大了");
}
if(n == ranNum) {
System.out.println("猜对了");
}
}
}
//获取一个数二进制序列中所有偶数和奇数位,分别输出二进制序列
public static void main21(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int count = 0;
for (int i = 31; i >= 1; i -= 2) {
System.out.print( ((n >>> i) & 1) + " ");
}
System.out.println();
for (int i = 30; i >= 0; i -= 2) {
System.out.print( ((n >>> i) & 1) + " ");
}
}
//求0-999之间的所有水仙花数(水仙花数:一个三位数各个数字的立方和等于这个数本身)
public static void main20(String[] args) {
Scanner scanner = new Scanner(System.in);
int j = scanner.nextInt();
for (int i = 0; i <= j; i++) {
int n = i;
int count = 0;
double sum = 0;
while(n != 0) {
count++;
n = n / 10;
}
n = i;
while(n != 0) {
sum += Math.pow(n % 10,count);
n /= 10;
}
if(i == sum) {
System.out.println(i);
}
}
}
//1-100的所有数字出现了多少个9
public static void main19(String[] args) {
int count = 0;
for (int i = 1; i <= 100; i++) {
if(i % 10 == 9) {
count++;
}
if(i / 10 == 9) {
count++;
}
}
System.out.println(count);
}
//输出一个整数的每一位
public static void func(int n) {
while(n != 0) {
int c = n % 10;
n = n / 10;
System.out.print(c + ",");
}
}
public static void main18(String[] args) {
func(125);
}
//实现一个两位数相加的方法
public static int add(int a,int b) {
return a+b;
}
public static void main17(String[] args) {
int ret = add(3,4);
System.out.println(ret);
}
//计算1/1-1/2+1/3-1/4+1/5......+1/99-1/100
public static double sum () {
double j = 1.0;
double sum = 0;
for (int i = 1; i <= 100; i++) {
sum += j / i;
j = -j;
}
return sum;
}
public static void main16(String[] args) {
double ret = sum();
System.out.println(ret);
}
public static void main15(String[] args) {
double j = 1.0;
double sum = 0;
for (int i = 1; i <= 100; i++) {
sum += j / i;
j = -j;
}
System.out.println(sum);
}
//写一个函数返回参数二进制中1的个数
public static void main14(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int count = 0;
while(n != 0) {
n = n & (n - 1);
count++;
}
System.out.println(count);
}
public static void main13(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int count = 0;
while(n != 0) {
if((n & 1) == 1) {
count++;
}
n = n >>> 1;
}
System.out.println(count);
}
public static void main12(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int count = 0;
for (int i = 1; i <= 32; i++) {
if(((n >>> i) & 1) ==1) {
count++;
}
}
System.out.println(count);
}
//求两个正整数最大公约数
public static void main11(String[] args) {
Scanner scan = new Scanner(System.in);
int a = scan.nextInt();
int b = scan.nextInt();