当前位置:网站首页>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();
}
}

边栏推荐
- ORM common requirements
- Wkid in ArcGIS
- 【MySQL提权】UDF提权(附带大马)
- Binder原理
- Perform Jieba word segmentation on the required content and output EXCEL documents according to word frequency
- IPv4 addresses have been completely exhausted, and the Internet can work normally. NAT is the greatest contributor!
- Solve several common problems
- Box model (2)
- Wechat applet (anti shake, throttling), which solves the problem that users keep pulling down refresh requests or clicking buttons to submit information; Get the list information and refresh the data
- QT log file system
猜你喜欢

Share two music playing addresses

编译器引论

According to the use and configuration of data permissions in the open source framework
![[training Day11] Calc [mathematics]](/img/a7/cbb33f0c241e1bad90a282bba990d1.png)
[training Day11] Calc [mathematics]

Multi data source switching
![[training day15] simple calculation [tree array] [mathematics]](/img/20/a5604f666ab02f47929f80c5597f0a.png)
[training day15] simple calculation [tree array] [mathematics]

Builder pattern

Why should we launch getaverse?

3dslicer introduction and installation tutorial

ML-Numpy
随机推荐
Common source code for ArcGIS development
【集训DAY13】Out race【数学】【动态规划】
数学规划分类 Math Programming Classfication
JSON object
[training day15] good name [hash]
scrapy无缝对接布隆过滤器
JS interview questions
3 lexical analysis
ECMA 262 12 Lexical Grammer
Ffmpeg plays audio and video, time_ Base solves the problem of audio synchronization and SDL renders the picture
分割金条的代价
对需求的内容进行jieba分词并按词频排序输出excel文档
分享两个音乐播放地址
[training day13] backpack [dynamic planning] [greed]
[training Day12] x equation [high precision] [mathematics]
If jimureport building block report is integrated according to the framework
(1) Integrating two mapping frameworks of Dao
The third programming competition of Wuhan University of technology b- save the kingdom of DAG (topological properties deal with accessibility Statistics)
我们为什么要推出Getaverse?
If it is modified according to the name of the framework module