SWT301_-_FA_2023_-_PE12_1281.webp
N

SWT301_-_FA_2023_-_PE12_1281.webp

Students are not allowed to use IDEs such as NetBeans, IntelliJ IDEA, or similar software to do the test.
Question 1 (3 points): Review the following class and find (at least) 6 issues in the code (i.e.,coding practice, compile errors, potential logical issues, etc.) (Use question 1 template)
public import java.util.Scanner;
class LongestString Finder {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String[] strings = null;
String LONGEST_STRING = null;
int stringCount;
System.out.print("Enter the number of strings: ");
stringCount = scanner.nextInt();
scanner.nextLine();
strings = new String[stringCount];
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
}
20
21
10
22
23
24
}
25
}
26
27
System.out.println("The longest string is: " + LONGEST_STRING);
28
}
}
29
for
(int i = 0; i < stringCount; i++) {
System.out.print("Enter string #" + (i+1) + ": ");
strings[i] = scanner.nextLine();
for (int i = 0; i <= stringCount; i++) {
if (strings[i].length() > LONGEST_STRING.length()) {
LONGEST_STRING = strings[i];
Zoom

+ 100%
Close
Chưa có bình luận nào.

Thông tin

Category
SWT301
Thêm bởi
Ngọc Trinh1
Ngày thêm
Lượt xem
2,322
Lượt bình luận
0
Rating
0.00 star(s) 0 đánh giá

Image metadata

Filename
SWT301_-_FA_2023_-_PE12_1281.webp
File size
70 KB
Dimensions
1936px x 868px

Share this media

Back
Bên trên Bottom