【无标题】定义

一, 定义两个int变量,判断并打印最大值

package ReStury.Homework;
​
import java.util.Scanner;
​
public class first {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入a");
        int a=sc.nextInt();
        System.out.println("请输入b");
        int b=sc.nextInt();
        if (a>b){
            System.out.println(a);
        }else {
            System.out.println(b);
        }
    }
}

二, 定义两个int变量x和y,分别为它们赋值, 然后比较x和y是否相等,把比较的结果赋值给一个boolean类型 变量并且打印出这个结果

package ReStury.Homework;
​
public class secend {
    public static void main(String[] args) {
        int x=3;
        int y=4;
        boolean bo=true;
        if (x>y){
            System.out.println(bo);
        }else if (x<y){
            System.out.println(!bo);
        }
​
        
    }
}

三, 定义一个整数变量x,给x赋值,判断x是不是偶数?

int a=4;
if (a%2==0){
    System.out.println(a+"是偶数");
}else {
    System.out.println(a+"不是偶数");
}

四, 定义一个整数变量year表示年份,为变量赋值, 判断这个年份是不是闰年,将判断的结果 xx是闰年 xx不是闰年 并且打印这个结果。闰年判断的依据是: 这个年份能被4整除且不能被100整除, 或者这个年份能被400整除, 这样的年份就是闰年。

Scanner sc=new Scanner(System.in);
System.out.println("请输入年份");
int year=sc.nextInt();
if (year%4==0&&year%100!=0 ||year%400==0){
    System.out.println(year+"年是润年");
}else {
    System.out.println(year+"年不是闰年");
}

五,

从控制台输入一个三位数,判断是否是水仙花数
水仙花数:数字本身值时个位,十位,百位,三个值的三次方之和
提示: a的三次方: a*a*a    370

 Scanner sc=new Scanner(System.in);
 System.out.println("请输入一个三位数");
​
int a=sc.nextInt();
if ((a/100)*(a/100)*(a/100)+(a%100/10)*(a%100/10)*(a%100/10)+(a%100%10)*(a%100%10)*(a%100%10)==a){
    System.out.println(a+"是水仙花");
}else {
    System.out.println(a+"不是水仙花");
}
六定义三个数据,求最大值

 Scanner sc=new Scanner(System.in);
System.out.println("请输入三个数字");
  int a=sc.nextInt();
  int b=sc.nextInt();
  int c=sc.nextInt();
  if (a-b>0&&a-c>0){
      System.out.println(a+"是最大值");
  }else if (b-a>0&&b-c>0){
      System.out.println(b+"是最大值");
  }else if (c-a>0&&c-b>0){
      System.out.println(c+"是最大值");
  }else {
      System.out.println("傻逼吧你是");
  }

七, 从控制台输入一个成绩等级,显示出中文等级 [两种实现方式] 注意:输入数据有误也要单独处理

   boolean bo=true;
        while (bo){
            System.out.println("请输入成绩等级");
            String s=sc.next();
            char a=s.charAt(0);
            switch (a){
                case 'A':
                    System.out.println("nb啊");
                    break;
                case 'B':
                    System.out.println("哎呦不错哟");
                    break;
                case 'C':
                    System.out.println("加油宝贝");
                    break;
                case 'D':
                    System.out.println("不行啊宝贝");
                    break;
                case 'E':
                    System.out.println("滚!别说我教过你");
                    break;
                default:
                    System.out.println("傻逼输错了");
            }
        }
    }
}
 boolean bo=true;
        while (bo){
            System.out.println("请输入成绩等级");
            String s=sc.next();
            char a=s.charAt(0);
           if (a== 'A'){
               System.out.println("nb啊");
           }else if (a=='B'){
               System.out.println("哎呦不错哟");
           }else if (a=='C'){
               System.out.println("加油宝贝");
           }else if (a=='D'){
               System.out.println("不行啊宝贝");
           }else if (a=='E'){
               System.out.println("滚!别说我教过你!");
           }else {
               System.out.println("手残人士");
           }

八、1.功能描述:定义一个变量代表月份,输出对应的季节 2.要求: (1)从控制台输入一个整数(代表月份,范围1-12) (2)输出该月份对应的季节 3,4,5春季 6,7,8夏季 9,10,11秋季 12,1,2冬季 (3)演示格式如下: 月份:3 控制台输出: 春季

package ReStury.Homework;
​
import java.util.Scanner;
​
public class DIBA {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
​
        boolean bo=true;
        while (bo){
            System.out.println("请输入月份");
            int month=sc.nextInt();
            if (month>=3&&month<=5){
                System.out.println(month+"月份是是春天");
            }else if (month>5&&month<=8){
                System.out.println(month+"月份是是夏天");
            }else if (month>8&&month<=11){
                System.out.println(month+"月份是是秋天");
            }else if (month<=2||month==12){
                System.out.println(month+"月份是是冬天");
            }else {
                System.out.println("白吃饭了月份都分不清");
            }
​
        }
    }
}

九,

编写一个JAVA程序,计算并显示某人根据下面确定的周薪:
如果工作时间小于等于40小时,那么每小时8美元;
否则,该职员在320美元基础上,对超过40小时的部分,再加上12美元每小时。
你所编写的程序应该请求输入工作时间数,并将得到的薪水显示出来。
package ReStury.Homework;
​
import java.util.Scanner;
import java.util.zip.Inflater;
​
public class xinshui {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        boolean bo=true;
        while (bo){
        System.out.println("请输入本月工作时长");
        int a=sc.nextInt();
        if (a<=40){
            System.out.println(a*8+"是他的工资");
        }else{
            System.out.println((a-40)*12+320+"是他的工资");
        }
    }
    }
}

十, 看程序说结果,注意不要提前运行代码。 public class Test { public static void main(String[] args) { short s = 30; int i = 50; s += i; System.out.println("s="+s); s=80; int x = 0; int y = 0; int z = 0; boolean b;

        b = x>0 && z++>1;
        x++;
        System.out.println("b="+b); fales
        System.out.println("z="+z); 0
​
        b = x>0 || z++>1;
        System.out.println("b="+b);  true
        System.out.println("z="+z);  0
    }
}

十一, 用程序实现如下不等式 1. 0 < x < 5

    x>0 && x<5  
        
    2. 10 <= a <= 20
    
    a>=10 && a<=20  
        
    3. b < 5 或者 b > 10
    
    b>5 || b<10 
        
    4. 0 < c < 5 或者 10 < c < 20
​
    (c>0 && c<5) || (c>10 && c<20)

十二, 编写一个体重检测器 要求:从控制台输入身高和体重,判断身体健康 体质指数(BMI)=体重(kg)÷身高^2(m) //==身高的二次方 例如:70÷(1.75×1.75)=22.86

BMI标准:
    偏瘦    <18.5 
    正常    18.5-23.9  
    偏胖    24-27.9   
    肥胖    28 - 30
    重度肥胖    30 - 40 
    极重度肥胖   ≥40.0
    package ReStury.Homework;
​
import java.util.Scanner;
​
public class tizhogn {
​
​
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
​
        boolean bo=true;
        while (bo){
            System.out.println("请输入体重");
            double w=sc.nextDouble();
            System.out.println("请输入身高");
            double h=sc.nextDouble();
            double BMI=w/(h*h);
            if (BMI<18.8){
                System.out.println("你太瘦啦");
            }else if (BMI>=18.5&&BMI<=23.9){
                System.out.println("你体重正常");
            }else if (BMI>=24&&BMI<=27.9){
                System.out.println("你体重偏胖");
            }
            else if (BMI>=28&&BMI<=30){
                System.out.println("你体重肥胖");
            }else if (BMI>30&&BMI<=40){
                System.out.println("你重度肥胖");
            }
            else if (BMI>=40){
                System.out.println("你体重极度肥胖");
            }
        }
    }
}
​
​
​
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    package ReStury.Homework;
​
public class nonine {
    public static void main(String[] args) {
​
        for (int i = 0; i < 100; i++) {
​
            if (i%10!=9&&i/10!=9){
                System.out.println(i);
​
            }
​
        }
​
    }
}
​

十三, 打印1到100之内的整数,但数字中包含9和被9整除的要跳过

package ReStury.Homework;
​
public class nonine {
    public static void main(String[] args) {
        int sum=0;
        for (int i = 0; i < 100; i++) {
​
            if (i%10!=9&&i/10!=9){
​
                sum+=i;
            }
​
        }
        System.out.println(sum);
    }
}

十四, 求1-10所有阶乘的和

int jc=1;
int jc2=1;
for(int i=1;i<=10;i++){
   if (i%2==0){
       jc*=i;
   }else {
       jc2*=i;
   }
}
    System.out.println(jc);
    System.out.println(jc2);
    System.out.println(jc+jc2);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值