Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit91643b5

Browse files
authored
Create Newsfeed3.java
1 parentcff4dbe commit91643b5

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
importjava.util.Arrays;
2+
3+
publicclassNewsfeed {
4+
5+
String[]topics = {"Opinion","Tech","Science","Health"};
6+
int[]views = {0,0,0,0};
7+
8+
publicNewsfeed(){
9+
10+
}
11+
12+
publicString[]getTopics(){
13+
returntopics;
14+
}
15+
16+
publicStringgetTopTopic(){
17+
18+
returntopics[1];
19+
}
20+
21+
publicvoidviewTopic(inttopicIndex){
22+
topicIndex ++;
23+
}
24+
25+
publicstaticvoidmain(String[]args){
26+
NewsfeedsampleFeed =newNewsfeed();
27+
28+
System.out.println("The top topic is "+sampleFeed.getTopTopic());
29+
30+
sampleFeed.viewTopic(1);
31+
sampleFeed.viewTopic(1);
32+
sampleFeed.viewTopic(3);
33+
sampleFeed.viewTopic(2);
34+
sampleFeed.viewTopic(2);
35+
sampleFeed.viewTopic(1);
36+
37+
System.out.println("The " +sampleFeed.topics[1] +" topic has been viewed " +sampleFeed.views[0] +" times!");
38+
}
39+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp