- 2
- 0
- 约7.98千字
- 约 20页
- 2016-08-30 发布于贵州
- 举报
1.结构化程序设计有哪三种流程?他们分别对应Java中那些语句。
结构化程序设计有三种基本流程:循环、分支和顺序。Java程序中的分支语句包含if语句、switch语句;循环语句包括了while语句,do-while语句、for语句;其他语句如变量、对象定义、赋值语句、方法调用语句、以及上面的循环结构、分支结构等按照上下文排列都是顺序语句。
2.在一个循环中使用break、continue和return有什么不同?
break用于跳出整个循环语句,在循环结构中一旦遇到break语句,不管循环条件如何,程序立即退出所在的循环体。
continue用于跳过本次循环中尚未执行的语句,但是仍然继续执行下一次循环中的语句。
在循环中使用return语句,将终止当前方法调用,同时终止循环,使流程返回到调用语句的下一个语句执行。
3.面代码将输出:________
a=9;b=18;c=4;d=14;e=-14;f=-2
g=18.4;h=2.3999999999999986;i=5;j=3;k=5
public class test3{
public static void main(String args[]){
int a=5+4;
int b=a*2;
int c=b/4;
int d=b-c;
int e=-d;
int f=e%4;
double g=18.4;
double h=g%4;
int i=3;
int j=i++;
int k=++i;
System.out.println(“a=”+a+”;b=”+b+”;c=”+c+”;d=”+d+”;e=”+e+”;f=”+f);
System.out.println(“g=”+g+”;h=”+h+”;i=”+i+”;j=”+j+”;k=”+k);
}
}
4.下面代码将输出:________
25<3=false
3!=025/35=true
0!=025/05=false
public class LogicTest{
public static void main(String args[]){
int a=25,b=3;
boolean d=ab; //d=false
System.out.println(a+”<“+b+”=”+d);//=;
int e=3;
d=(e!=0a/e5);
System.out.println(e+”!=0”+a+”/”+e+”5=”+d);
int f=0;
d=(f!=0a/f5);
System.out.println(f+”!=0”+a+”/”+f+”5=”+d);
}
}
5.编写程序,求两个整数的最大公约数。
import java.util.Scanner;
public class Gcd_Lcm{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
System.out.println(“输入2个数:以‘,’ 隔开“);
String []str = sc.next().split(“,”);
int m = Integer.parseInt(str[0]);
int n = Integer.parseInt(str[1]);
int min = mn?n:m;
int max = mn?m:n;
int num1 =1;
int num2 = max;
for (int i = min; i0; i–) {
if (m%i==0n%i==0) {
num1 = i;break;
}
}
while (true) {
if (num2%m==0num2%n==0) {
break;
}
num2 = m*nnum2*2?num2*2:m*n;
}
System.out.println(“最大公约数:“+num1+” 最小公倍数:”+num2);
}
}
6.编写程序,打印出如下九九乘法表。
* | 1 2 3 4 5 6 7 8 9
——-|——————————————————-
1 | 1
2 | 2 4
3 | 3 6 9
4 | 4 8 12 16
5 | 5 10 15 20 25
6 | 6 12 18 24 30 36
7 | 7 14 21 28 35 42 49
8 | 8 16 24 32 40 48 56 64
9 | 9 18 27 36 45 54 63 72 81
public class NineByNineMul{
public static void main(String args[]){
System.out.print(“ * |”);
for(int i=1;i=9;i++
您可能关注的文档
最近下载
- 上海大学2022-2023学年第1学期《高等数学(上)》期末考试试卷(A卷)附参考答案.pdf
- 中国教育行业人才流动与薪酬水平_2025年12月.docx
- 2024全国初中数学联赛初二卷 .pdf VIP
- 全国初中数学联合竞赛真题及答案(初二组)2015-年.pdf VIP
- AIAG-VDA-SPC手册-Yellow-Volume2026年2月第一版 中文.pdf VIP
- 美甲美睫投资回报2026年培训课件.pptx VIP
- 中国王氏家谱字辈大全.doc VIP
- 《Michael_Porter_Creating_Shared_Value》.pdf VIP
- 直播带货虚假宣传法律规制研究.pdf
- 新大洲本田MS01说明书用户手册.pdf
原创力文档

文档评论(0)