2つの異なるクラスに2つのメソッドがあります。私は彼らに同じ入力行を読んで、異なるものをチェックしてほしい。2つの異なるメソッドで同じ入力を2回読み取る
public class Class1(){
public void PleaseAndThankYous(){
Scanner scanner1 = new Scanner(System.in)
input1 = Scanner1.nextLine();
if (input1.contains//blah blah blah blah...
public class Intructions(){
public void Method2(){
Scanner scanner2 = new Scanner(System.in)
input2 = Scanner2.nextLine();
if (input1.contains//blah blah blah blah...
、その後、私は:一つは「私コーヒー作り」と「してください」などのさまざまなキーワードの他のルックスと(プログラムが私にどのように応答するか、これらの効果)「ありがとう」などの取扱説明書を探しますちょうどそれらをテストするために、私のメインの文字列でそれらを呼び出す:
System.out.println("this is a test, ask me something")
obj.PleaseAndThankYous();
obj.Intructions();
と、このように私のコンソールのプリントアウト:
this is a test, ask me something //(out put string)
make me a coffee please //PleaseAndThankYous() reads this
make me a coffee please // Intructions() reads this;
Making you a coffee, Sir. // (response)
起こっていただきました!私は理解しますが、私は別の方法を考えることはできません。 私は同じスキャナを使用しようとしましたが、異なる文字列を使用しましたが、それでも動作しませんでした。 両方のメソッドが最初の入力行を読み込み、2回すべて入力する必要がないようにするにはどうすればよいですか?ありがとう!
'main'の入力を読み込んだ後、文字列をパラメータとして' PleaseAndThankYous'と 'Intructions' –