当前位置:网站首页>Learning practice: comprehensive application of cycle and branch structure (I)
Learning practice: comprehensive application of cycle and branch structure (I)
2022-07-03 04:30:00 【ICErain0201】
1、 Use double loop to output 99 multiplication table
public class Test1 {
public static void main(String[] args) {
int i ,j;
// The outer loop outputs the first multiplier , The loop inside outputs the second multiplier
for(i = 1;i <= 9;i++) {
for(j = 1;j <= i;j++) {
System.out.print(i+" * "+j+" = "+i * j+"\t");
if(j == i) {
System.out.print("\n");
}
}
}
}
}
The output sample is as above
2、 Enter an integer from the keyboard , When the input 1~7 when , Output “ Monday ”~“ Sunday ” When entering other numbers , Prompt the user to re-enter , Input 0 End the program at .
package homework2;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int day;
do{
System.out.println(" Please enter 1--7 Number between , Input 0 Exit procedure ");
day = input.nextInt();
// Input 1 To 7 Output the corresponding week , Enter other non 0 Digital pop-up prompt
switch(day) {
case 0:
break;
case 1:
System.out.println(" Monday ");
break;
case 2:
System.out.println(" Tuesday ");
break;
case 3:
System.out.println(" Wednesday ");
break;
case 4:
System.out.println(" Thursday ");
break;
case 5:
System.out.println(" Friday ");
break;
case 6:
System.out.println(" Saturday ");
break;
case 7:
System.out.println(" Sunday ");
break;
default:
System.out.println(" The input data must be 0 To 7 Between ");
}
}while(day!=0);
// Input 0 End the program at
System.out.println(" Program end ");
}
}
The test example is as above
3、 The digital pyramid
package homework3;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println(" Please enter an integer ");
int n = input.nextInt();
int i,j,k;
// The following loop outputs the number of lines
for(i = 1;i<=n;i++) {
// The following loop outputs spaces
for(j=0;j<=n-i;j++) {
System.out.print(" ");
}
// The following loop outputs numbers
for(k=1;k<=2*i-1;k++) {
System.out.print(i);
}
System.out.print("\n");
}
}
}
The test example is as above
边栏推荐
- [set theory] binary relationship (special relationship type | empty relationship | identity relationship | global relationship | divisive relationship | size relationship)
- [free completion] development of course guidance platform (source code +lunwen)
- Wine travel Jianghu War: Ctrip is strong, meituan is strong, and Tiktok is fighting
- GFS分布式文件系统(光是遇见已经很美好了)
- C language series - Section 3 - functions
- [NLP]—sparse neural network最新工作简述
- Golang -- realize file transfer
- Contents of welder (primary) examination and welder (primary) examination in 2022
- Solve BP Chinese garbled code
- 金仓数据库KingbaseES 插件kdb_database_link
猜你喜欢
跨境电商多商户系统怎么选
[nlp] - brief introduction to the latest work of spark neural network
BMZCTF simple_ pop
After job hopping at the end of the year, I interviewed more than 30 companies in two weeks and finally landed
Daily question - ugly number
Basic use of continuous integration server Jenkins
Function introduction of member points mall system
The latest activation free version of Omni toolbox
2022 chemical automation control instrument examination summary and chemical automation control instrument certificate examination
Two drawing interfaces - 1 Matlab style interface
随机推荐
[set theory] binary relationship (definition field | value field | inverse operation | inverse synthesis operation | restriction | image | single root | single value | nature of synthesis operation)
Know that Chuangyu cloud monitoring - scanv Max update: Ecology OA unauthorized server request forgery and other two vulnerabilities can be detected
使用BENCHMARKSQL工具对kingbaseES执行灌数据提示无法找到JDBC driver
AWS VPC
BMZCTF simple_ pop
I've been in software testing for 8 years and worked as a test leader for 3 years. I can also be a programmer if I'm not a professional
Mongodb slow query optimization analysis strategy
Use the benchmarksql tool to perform a data prompt on kingbases. The jdbc driver cannot be found
Integration of Android high-frequency interview questions (including reference answers)
Drf--- quick start 01
Internationalization and localization, dark mode and dark mode in compose
When using the benchmarksql tool to preheat data for kingbasees, execute: select sys_ Prewarm ('ndx_oorder_2 ') error
PostgreSQL database high availability Patroni source code learning - etcd class
2022 tea master (intermediate) examination questions and tea master (intermediate) examination skills
Redis persistence principle
[untitled] 2022 safety production supervisor examination question bank and simulated safety production supervisor examination questions
[set theory] ordered pair (ordered pair | ordered triple | ordered n ancestor)
Pdf editing tool movavi pdfchef 2022 direct download
MySQL field userid comma separated save by userid query
How to use kotlin to improve productivity: kotlin tips