2017-10-04 14 views
-1

我的程序需要掃描單個字符,直到「。」用戶輸入點。
然後打印出來像下面我需要掃描多個字符,直到「。」然後打印它們

THE OUTPUT 
Hello! I print out an acronym. 
Please, enter a character: 
i 
Please, enter a character: 
d 
Please, enter a character: 
k 
Please, enter a character: 
. 
i.d.k. 
+1

歡迎Eemil to stackoverflow,請顯示您的代碼 – ravi

+0

我一直被卡住了一切如何做到這一點如果其他? –

回答

-1

輸出。如果你想與控制檯使用本作品:

System.out.print("Please, enter a character:"); //printing text to console 
String input = System.console().readLine(); //reading the string 

字符串的字符轉換:char c = input.charAt(0);

與循環來工作讓你的代碼像你想要的那樣工作:https://docs.oracle.com/javase/tutorial/java/nutsandbolts/for.html

0

試試這個吧,

import java.util.*; 
public class MyClass { 
    public static void main(String args[]) { 
     Scanner s = new Scanner(System.in); 
     String input; 
     String output = ""; 
     do{ 
      System.out.println("Please Enter a Character"); 
      input = s.nextLine(); 
      output = output+"."+input; 
     }while(!input.equals(".")); 
     System.out.println(output); 
    } 
} 
+0

輸出來了.i.d.k ..但生病了。感謝幫助! –

相關問題