if语句

求三个数的最大值
public class Tes{
public static void main(String[] args) {
int a = 10;
int b = 20;
int c = 30;
int max;
if (a > b){if (a > c){max = a;
}else {
max = c;
}
}else {
if (b < c){max = c;
}else {
max = b;
}
}
System.out.println("max = " + max);
}
在这里插入图片描述

输入一个整数,判断这个整数是大于0,还是小于0,还是等于0。
public class ooo {
public static void main(String []args){
System.out.println(“请输入一个整数:”);
int b=s.nextInt();
if(b>0){
System.out.println(“输入的整数大于0!”);
}else if(b<0){
System.out.println(“输入的整数小于0!”);
}else {
System.out.println(“输入的整数为0!”);
}
}
在这里插入图片描述

用 if…else 语句判断一个输入的数是否为奇数
public class Tea {
public static void main(String[] args) {
System.out.println(“输入一个整数:”);
if(num % 2 != 0) {
System.out.println(“奇数”);
} else {
System.out.println(“偶数”);
}
}
}

在这里插入图片描述

判断2020年是否为闰年
public class runnian{
public static void main(String args[]){
int year=2020;
if((year%40&&year%100!=0)|| (year%4000))
System.out.print(year+“是闰年”);
else
System.out.print(year+“不是闰年”);
}
}

在这里插入图片描述

判断是否可以进入网吧
public class Ufo{
public static void main(String[]args){
a = int(input('请输入你的出生年月);
b=2020;
age=b-a;
System.out.print(‘你的年龄是:%d’%age);
if age>=18;{
System.out.print(‘可以进入网吧’);
}else{
System.out.print(‘未满18岁,禁止进入网吧!’);
}

在这里插入图片描述

我家的狗5岁了, 5岁的狗相当于人类多大呢?其实,狗的前两年每一年相当于人类的10.5岁,之后每增加一年就增加四岁。那么5岁的狗相当于人类多少年龄呢?(应该是: 10.5 + 10.5 + 4 + 4 + 4 = 33岁。)

public class Test5 {
public static void main(String[] args) { Scanner dogAge= new
Scanner(System.in);
int age=dogAge.nextInt();
if(age>0 && age<=2){ System.out.println(“相当于人的年龄:” + age * 10.5);
}else if(age>2){
System.out.println(“相当于人的年龄:” + (2* 10.5+(age-2)*4));
}else{
System.out.println(“狗狗还没出生”);
}
}

在这里插入图片描述

操场上100多人排队,三人一组多1人,四人一组多2人,五人一组多3人,共多少人?(118,178)
public class z1 {
public static void main(String[] args) {
for(int i=100;i<200;i++){
if(i%31 && i%42 && i%5==3){ System.out.println(“操场上有”+i+“人”);
}
}
}

在这里插入图片描述

用户登录(三次机会重试)
public class ccc{
public static vuid main(String[]args{
for i in range(3) ;
a=input(“账号:”);
b=input(“密码:”);
if a == ‘cgc’ and b==‘123’ ; system.out.print(‘登陆成功’);
breakelse;
System.out.print(‘账号或者密码错误!’) ;
}
}

在这里插入图片描述

if…else实现求两个数中的最大值
public class Lx{
public static void main(String[]args{
int num1=10;
int num2=1;
int max=0
if(num1>num2{
max=num1;
}else{
max=num2;
}
System.out.println(num1+“和”+num2+“最大的是”+max);
}
}
在这里插入图片描述
if实现两个数中求最值
public class 01{
public static void main(String[]args{
int num1=10;
int num2=1;
int max=num2;
if(num1>max){
max=num1;
}
System.out.println(num1+“和”+num2+“最大
的是”+max);
}
}

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值