ifelse练习彩票问题

源代码:

package javaexer;
import java.util.Scanner;
public class doublecoloredbulb {
    public static void main(String[] agr) {
        Scanner scanner=new Scanner(System.in);
        int oneprice=(int)(Math.random()*90+10);
        System.out.println("请输入您选择的号码:");
        int num=scanner.nextInt();
        if(num==oneprice) {
            System.out.println("恭喜您获得10000美元");
        }
        else if(num==(oneprice%10*10+oneprice/10)) {
            System.out.println("恭喜您获得3000美元");    
            System.out.println("中奖号码是:"+oneprice);
        }
        else if((num%10)==(oneprice%10)||(num/10)==(oneprice/10)) {
            System.out.println("恭喜您获得1000美元");
            System.out.println("中奖号码是:"+oneprice);
        }
        else if((num%10)==(oneprice%10)||(num/10)==(oneprice/10)||(num%10)==(oneprice/10)||(num/10)==(oneprice%10)) {
            System.out.println("恭喜您获得500美元");
            System.out.println("中奖号码是:"+oneprice);
        }
        else {
            System.out.println("很遗憾你没有中奖");
            System.out.println("中奖号码是:"+oneprice);
        }
    }

}
 

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是 Python if else 练习题: 1. 编写一个程序,判断一个数是否为偶数。 ```python num = int(input("请输入一个整数:")) if num % 2 == 0: print(num, "是偶数") else: print(num, "不是偶数") ``` 2. 编写一个程序,判断一个年份是否为闰年。 ```python year = int(input("请输入一个年份:")) if (year % 4 == 0 and year % 100 != 0) or year % 400 == 0: print(year, "是闰年") else: print(year, "不是闰年") ``` 3. 编写一个程序,输入三个数,输出其中最大的数。 ```python a = float(input("请输入第一个数:")) b = float(input("请输入第二个数:")) c = float(input("请输入第三个数:")) if a >= b and a >= c: print(a, "是最大的数") elif b >= a and b >= c: print(b, "是最大的数") else: print(c, "是最大的数") ``` 4. 编写一个程序,输入三个数,输出其中最小的数。 ```python a = float(input("请输入第一个数:")) b = float(input("请输入第二个数:")) c = float(input("请输入第三个数:")) if a <= b and a <= c: print(a, "是最小的数") elif b <= a and b <= c: print(b, "是最小的数") else: print(c, "是最小的数") ``` 5. 编写一个程序,输入一个字符,判断它是大写字母、小写字母还是数字。 ```python ch = input("请输入一个字符:") if ch.isupper(): print(ch, "是大写字母") elif ch.islower(): print(ch, "是小写字母") elif ch.isdigit(): print(ch, "是数字") else: print(ch, "不是大写字母、小写字母或数字") ``` 6. 编写一个程序,输入一个年龄,判断它是否为儿童(0-12岁)、青少年(13-18岁)或成年人(19岁及以上)。 ```python age = int(input("请输入一个年龄:")) if age < 0: print("输入有误") elif age <= 12: print("儿童") elif age <= 18: print("青少年") else: print("成年人") ``` 7. 编写一个程序,输入一个月份,输出该月份的天数。 ```python month = int(input("请输入一个月份:")) if month in [1, 3, 5, 7, 8, 10, 12]: print(month, "月有31天") elif month in [4, 6, 9, 11]: print(month, "月有30天") elif month == 2: year = int(input("请输入一个年份:")) if (year % 4 == 0 and year % 100 != 0) or year % 400 == 0: print(month, "月有29天") else: print(month, "月有28天") else: print("输入有误") ```

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值