我的第一篇文章在stackoverflow上。 任務是: 編寫一個方法,該方法返回一個字符串,該方法沒有參數。該方法將從鍵盤讀取一些單詞。該輸入字「END」的方法應該返回這整個文本作爲一長排結束:Java返回輸入文本
"HI" "HELLO" "HOW" "END"
提出的是,這樣的方法會返回一個字符串
HIHELLOHOW
我的代碼是:
import java.util.*;
public class Upg13_IS_IT_tenta {
String x, y, c, v;
public String text(){
System.out.println("Enter your first letter");
Scanner sc = new Scanner(System.in); //Can you even make this outside main?
x = sc.next();
y = sc.next();
c = sc.next();
v = sc.next(); // Here I assign every word with a variable which i later will return. (at the bottom //i write return x + y + c;). This is so that i get the string "HIHELLOWHOW"
sc.next();
sc.next();
sc.next();
sc.next(); // Here I want to return all the input text as a long row
return x + y + c;
}
}
我知道,我的代碼有很多在它的錯誤,我是新來的Java,所以我想這樣的幫助和什麼我解釋我做錯了。謝謝!