解题思路:利用split()函数将字符串以空格分割成数组储存
参考代码:
import java.util.LinkedList;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String line = scanner.nextLine();
String [] words = line.split(" ");
LinkedList<String> wordsL = new LinkedList<String>();
int SUM = 0;
wordsL.add(words[0]);
for (int i = 0; i < words.length; i++) {
SUM = 0;
String str1 = words[i];
for (int j = 0; j < wordsL.size(); j++) {
if (str1.equals(wordsL.get(j))){
SUM++;
}
}
if (SUM == 0){
wordsL.add(str1);
}
}
System.out.println(wordsL.size());
}
}
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题10.5 (C语言代码)浏览:566 |
IP判断 (C语言代码)浏览:820 |
A+B for Input-Output Practice (III) (C语言代码)浏览:594 |
图形输出 (C语言代码)浏览:1422 |
The 3n + 1 problem (C语言代码)浏览:550 |
矩形面积交 (C语言代码)浏览:1433 |
C语言程序设计教程(第三版)课后习题12.3 (C语言代码)浏览:587 |
C语言程序设计教程(第三版)课后习题7.3 (C语言代码)浏览:420 |
C二级辅导-分段函数 (C语言代码)浏览:790 |
1073题解浏览:652 |