当前位置:网站首页>Day006 select structure (if statement exercise)
Day006 select structure (if statement exercise)
2022-07-25 22:39:00 【Mo Nian】
Catalog
1、 Use if Select the structure to judge whether an integer is even or odd .
2、 Use if Select the structure to judge whether a three digit integer is the number of daffodils .
Conditions for the number of daffodils : Three figures are abc, Then meet :a3+b3+c3=abc
3、 Use if Select the structure to judge whether a year is a leap year .
The conditions of leap years :
4、 Judge the grade of this exam .
5、 Yes 3 It's an integer , Give tips :
Finally, output triangle area ;
1、 Use if Select the structure to judge whether an integer is even or odd .
package cn.bdqn.Demo03;
import java.util.Scanner;
public class practice111 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println(" Please enter an integer :");
int number = sc.nextInt();
System.out.println(" This integer is :"+number);
if(number%2==0){
System.out.println(" This integer is even ");
}else{
System.out.println(" This integer is odd ");
}
System.out.println(" This is the end of program execution ");
}

2、 Use if Select the structure to judge whether a three digit integer is the number of daffodils .
Conditions for the number of daffodils : Three figures are abc, Then meet :a3+b3+c3=abc
package cn.bdqn.Demo03;
import java.util.Scanner;
public class practice111 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println(" Please enter a three digit integer :");
int number = sc.nextInt();
System.out.println(" This three digit integer is :"+number);
int geWei = number%10;
int shiWei = number/10%10;
int baiWei = number/100%10;
if(geWei*geWei*geWei+shiWei*shiWei*shiWei+baiWei*baiWei*baiWei==number){
System.out.println(" This integer is the number of daffodils ");
}else{
System.out.println(" This number is not narcissus number ");
}
System.out.println(" This is the end of program execution ");
sc.close();
}
}


3、 Use if Select the structure to judge whether a year is a leap year .
The conditions of leap years :
Common leap year : Can be 4 Divide but not be 100 The year of division is a common leap year .( Such as 2004 Year is leap year );
Leap year of the century : Can be 400 Divisible into century leap years .( Such as 2000 Year is the leap year of the century );
package cn.bdqn.Demo03;
import java.util.Scanner;
public class practice111 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println(" Please enter a year :");
int year = sc.nextInt();
if(year%4==0&&year%100!=0){
System.out.println(" This year is an ordinary leap year ");
}else if(year%400==0){
System.out.println(" This year is the year of the century ");
}else{
System.out.println(" This year is not a wet year ");
}
System.out.println(" This is the end of program execution ");
sc.close();
}
}



4、 Judge the grade of this exam .
90-100 Between for excellent
80-89 Between is excellent
70-79 Between for good ,
60-69 Between for pass
60 Below is a failing grade .
package cn.bdqn.Demo03;
import java.util.Scanner;
public class practice111 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println(" Please enter the test scores :");
int grade = sc.nextInt();
System.out.println(" The test result is :"+grade);
if(grade>=90&&grade<=100){
System.out.println(" good ");
}else if(grade>=80){
System.out.println(" excellent ");
}else if(grade>=70){
System.out.println(" good ");
}else if(grade>=60){
System.out.println(" pass ");
}else{
System.out.println(" fail, ");
}
System.out.println(" This is the end of program execution ");
sc.close();
}
}


5、 Yes 3 It's an integer , Give tips :
Can I create triangles ;
If you can build triangles , Prompt is right triangle or equilateral triangle, isosceles triangle or ordinary triangle ;
Finally, output triangle area ;
package cn.bdqn.Demo03;
import java.util.Scanner;
public class practice111 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println(" Please enter three integers :");
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
double q=(a+b+c)/2.0;
double s=q*(q-a)*(q-b)*(q-c);
System.out.println(Math.sqrt(s));
if((a+b>c)||(a+c>b)||(b+c>a)){
if((a>b&&a>c&&b*b+c*c==a*a)||(b>a&&b>c&&c*c+a*a==b*b)||(c>a&&c>b&&a*a+b*b==c*c)){
System.out.println(" right triangle ");
//System.out.println(s);
}
else if(a==b&&a==c){
System.out.println(" Equilateral triangle ");
//System.out.println(s);
}
else if(a==b||a==c||b==c){
System.out.println(" an isosceles triangle ");
//System.out.println(s);
}else if((a+b<c)||(a+c<b)||(b+c<a)){
System.out.println(" Cannot build triangles ");
}
}else{
System.out.println(" Ordinary triangle ");
//System.out.println(s);
}
System.out.println(" This is the end of program execution ");
sc.close();
}
}

边栏推荐
- [training Day11] Calc [mathematics]
- Pyspark data analysis basis: pyspark.sql.sparksession class method explanation and operation + code display
- 面试题 17.11. 单词距离 ●●
- Floating effect and characteristics
- Use of hyperlinks
- Matrixcube unveils the complete distributed storage system matrixkv implemented in 102-300 lines
- 平台架构搭建
- Xiaobai programmer's first day
- Win10 set up a flutter environment to step on the pit diary
- 1000个Okaleido Tiger首发上线Binance NFT,引发抢购热潮
猜你喜欢

【集训DAY13】Travel【暴力】【动态规划】

Builder pattern

Basic principle of torque motor control

【PMP学习笔记】第1章 PMP体系引论

JVM内存区域

Matrixcube unveils the complete distributed storage system matrixkv implemented in 102-300 lines

【MySQL提权】UDF提权(附带大马)

【集训DAY11】Nescafe【贪心】

Why should we launch getaverse?

SMART S7-200 PLC通道自由映射功能块(DO_Map)
随机推荐
Array中可以用泛型吗
Compiler introduction
Multi data source switching
XSS tool beef XSS installation and use
torchvision
3dslicer importing medical image data
【集训DAY13】Out race【数学】【动态规划】
1000 okaleido tiger launched binance NFT, triggering a rush to buy
DOM event binding
Interpretation of the source code of all logging systems in XXL job (line by line source code interpretation)
IFLYTEK smart office book air e-book reader makes my work life healthier
IPv4 addresses have been completely exhausted, and the Internet can work normally. NAT is the greatest contributor!
Using simple scripts to process data in 3dslicer
ThreadLocal 总结(未完待续)
ThreadLocal summary (to be continued)
Select structure if branch structure
JVM memory area
【集训DAY13】Internet【并查集】
xxl-job中 关于所有日志系统的源码的解读(一行一行源码解读)
【集训DAY15】好名字【hash】