Java if loop basic exercises-22 days study notes

//Dog’s age is 10.5 times that of humans in the first two years, and
4 times in each year. Enter the dog’s age to get the age of a human, and output other errors.


public class Applicant
{
		public static void main (String[] args){
				
			  
					
Scanner input =new 	Scanner(System.in);
		System.out.println("输入狗的年龄");
  double dog = input.nextInt();
		
		
		if(dog <= 0 && dog <= 2 ){
				System.out.println(dog * 10.5);
		}else if (dog > 2)	{
			double year =	dog-2;
				System.out.println((dog * 10.5)+(year * 4));
		}else{
				System.out.println("输入不正确");
		}
		
	 

 input.close();
	

Lottery

|Suppose you want to develop a lottery game. The program randomly generates a two-digit lottery ticket, prompts the user to enter a two-digit number, and then determines whether the user can win according to the following rules.

1) If the number entered by the user matches the actual order of the lottery, the prize is $10,000.

2) If all the numbers entered by the user match all the numbers in the lottery, but the order is inconsistent, the prize is $3,000.

3) If the number entered by the user meets only one number of the matching lottery under the condition of the sequence, the prize is $1,000.

4) If a number entered by the user only satisfies one number of the matching lottery in a non-sequential situation, the prize is 500 USD.

5) If the number entered by the user does not match any number, the lottery ticket is invalid.

Tip: Use (int)(Math.random()*90 + 10) to generate random numbers.

Math.random(): [0,1) * 90 >[0,90) + 10 >[10,100) > [10,99]

//如何获取一个随机数 10-99
			 		System.out.println("欢迎使用彩票系统" + "\n"+ "请输入你买的两位彩票数字");
	
      Scanner input = new Scanner(System.in);
						
						int num1 = input.nextInt();
						
						int ten = num1 / 10;
						
						int single = num1 % 10;
					
					//借用Math类   random默认是double类型
					int num = (int)(Math.random()*90 + 10);
					/*默认0.0-1.0,所以我们把他乘100并且把他强转为int类型不要小数点
					但是题目是[10-90)  所以我们给他*90  得到 [0-90) 在把他数值+10
					得到左闭右开的 [10,100),也就是[10,99]
					*/
					System.out.println(""+num);
					
					//分别定义他的个位与十位
					int tenDigits = num / 10;//取十位数
					
					int singleDigits = num % 10;//取余
					
					if (num == num1){
							
							System.out.println("恭喜你获得奖金10000元");
							
					}else if (ten == singleDigits && single ==tenDigits){
							
								System.out.println("恭喜你获得奖金3000元");
								
					}else if (ten == singleDigits || single == tenDigits) {
							
								System.out.println("恭喜你获得奖金1000元");
							
					}else if (ten == tenDigits || single ==singleDigits) {
							
								System.out.println("恭喜你获得奖金500元");
							
					}else {
							
							System.out.println("这张彩票作废");
							
					}
					input.close();
			}

If you are over 180, you have 10 million, and if you are handsome, give it to him. If you are satisfied with one of them, you will not marry if you are not satisfied.

public class Practice5
{
		public static void main (String[] args){
				
				Scanner input = new Scanner(System.in);
				
					System.out.println("请输入你的身高cm");
					int hight = input.nextInt();
					System.out.println("请输入你的财富千万");
					double wealth = input.nextDouble();
				/*	方式1 System.out.println("你帅不帅"+"ture或false");
					boolean bety = input.nextBoolean();
					判断是否  用是和否或者yes 或no
					这样我们就可以用字符串表达
					*/
					System.out.println("你帅不帅 yes or no");
					String bety = input.next();
					
					//此处判断就需要用  .equals("")
					if(hight > 170 && wealth > 1000 && bety.equals("yes")){//布尔值判断可以不用写ture
					   System.out.println("嫁给他");
								}else if (hight > 170 || wealth > 1000 || bety.equals("no")){
										System.out.println("也还可以");
								}else{
										System.out.println("不嫁");
								}
					
		}
}

Guess you like

Origin blog.csdn.net/yibai_/article/details/115105076
Recommended