【新手继续求助..】= = 几个java program

来源:百度知道 编辑:UC知道 时间:2024/06/15 16:30:24
1. Create a program that reads in one line from the user and repeats the line back with all four-letter words removed. Save as StringEx1.java 就是说输入句子然后只要是四个字的就从句子中去掉..

我做的是import java.util.*;
public class StringEx1 {

public static void main (String[]args) {
Scanner keyboard = new Scanner(System.in);
String word="";
System.out.println("Enter one sentence: ");
String sent=keyboard.nextLine();

for (int i =0; i<sent.length();i++){

if(sent.charAt(i)==' '){
if (word.length()!=4){
System.out.print(word);
}
word = "";
}
else {
word=word+sent.charAt(i);
}
}
//System.out.println(word);
}

}

2. Creat a simple system where cut each line in half and build a new line by interleaving the letter from e

好像字符串 String 这个变量有问题 你要先给他赋值

嗯,我是来乱入的

错在那那

你第一个string没有赋值。假若不想赋值,应该初始化。
下面眼很花,不看了。