OOP - TB1 - Tutorial
2026/7/21 22:43:26 网站建设 项目流程

TB1 Tutorial


文章目录

  • TB1 Tutorial
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.

1.

answer:
less than 10

2.

answer:
yes

3.


注意前两个情况都没有break,所以程序会一直运行。
answer:
zero
none
one
zero
none
none

4.

Write a Java program that calculates the sum of integers in the range
1 to 100 (inclusive).

publicclassSum{publicstaticvoidmain(String[]args){intn=100;intsum=0;//一定要初始化为0,不能默认for(inti=0;i<=n;i++){sum+=i;}System.out.println(sum);}}

5.

publicclassMutiplicationTable{publicstaticvoidmain(String[]args){intn=3;intproduct=0;for(inti=1;i<=n;i++){for(intj=1;j<=n;j++){product=i*j;System.out.print(product+" ");}System.out.println();//记住换行的时候啥都不用写}}}

6.


answer:
9
8
true

7.

Write a block of code that calculates the sum of all the integers divisible by 3, in the range 1 to 99 (inclusive). You are not required to write a complete program.

publicclassSumDivisibleBy3{publicstaticvoidmain(String[]args){intsum=0;for(inti=1;i<100;i++){if((i%3)==0){sum+=i;}}System.out.println(sum);}}

8.


answer:

double[]numbers={3.5,6,2.6,8.0};int[]marks=newint[60];char[]letters={'a','b','c','d','e','f'};String[]books={"Java","SQL","PHP"};

9.


output:
Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: Index 5 out of bounds for length 5
at Test_Q2.main(Test_Q2.java:5)

Reason:
ishould less than intArray, rather than<=

10.


answer:
f[1] = new Flower();

11.

answer:
ArrayIndexOutOfBoundsException

12.

answer:
variable i might not have been initialized
int i=0;

13.


answer:
36
36.0

14.

publicclassStarsTriangle{publicstaticvoidmain(String[]args){introw=0;intsize=8;while(row<size){intcol=0;while(col<=row){System.out.print('*');col=col+1;}System.out.println();row=row+1;}}}

15.

Determine the question that should result in the following possible answers
Answer 1
“This happens when a class has multiple methods with the same name but different lists of parameters.
It helps ensure consistency when naming methods.”
Answer 2
“Methods in the same class that share the same name but accept different variable types as arguments. Such methods give programmers the flexibility to call a similar method with different types of data.”

answer:
What is method overloading in Java?

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询