Creating scanner with multiple wordsCreate ArrayList from arrayHow do I create a Java string from the contents of a file?How can I create an executable JAR with dependencies using Maven?How do I create a file and write to it in Java?Create the perfect JPA entityCreating a memory leak with JavaJava - Scanner(System.in) and “Blocking a thread”Scanner is skipping nextLine() after using next() or nextFoo()?Keep getting this error message for my RockPaperScissor Program. How do I fix this error?

Of strange atmospheres - the survivable but unbreathable

How to keep consistency across the application architecture as a team grows?

Who knighted this Game of Thrones character?

Where is Jon going?

Why sampling a periodic signal doesn't yield a periodic discrete signal?

Count all vowels in string

First Program Tic-Tac-Toe

Cardio work for Muay Thai fighters

Navigating a quick return to previous employer

Did this character show any indication of wanting to rule before S8E6?

Does French have the English "short i" vowel?

Using too much dialogue?

Creating second map without labels using QGIS?

Why isn't Tyrion mentioned in the in-universe book "A Song of Ice and Fire"?

Sorting with IComparable design

Must a warlock replace spells with new spells of exactly their Pact Magic spell slot level?

Is there any chance a man can get the death penalty for causing a miscarriage?

Why is this integration method not valid?

Why does Bran want to find Drogon?

A burglar's sunglasses, a lady's odyssey

Is superuser the same as root?

How would a developer who mostly fixed bugs for years at a company call out their contributions in their CV?

Can you still travel to America on the ESTA waiver program if you have been to Iran in transit?

Can a UK national work as a paid shop assistant in the USA?



Creating scanner with multiple words


Create ArrayList from arrayHow do I create a Java string from the contents of a file?How can I create an executable JAR with dependencies using Maven?How do I create a file and write to it in Java?Create the perfect JPA entityCreating a memory leak with JavaJava - Scanner(System.in) and “Blocking a thread”Scanner is skipping nextLine() after using next() or nextFoo()?Keep getting this error message for my RockPaperScissor Program. How do I fix this error?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















I need to include 10 variables but when I type in anything it comes up with only 1 of the variables I need to know how to make it so for example when "Gaming" is typed, the program comes back with "Do you like gaming?" right now it is at the point where anything I type it comes up with "Do you like uni?"



I have tried searching google for 3 hours and have done everything they have said and I can't find it. using .contains doesn't work for some reason.



 Scanner chatterbot = new Scanner(System.in); 
String uni = ("University");
String gaming = ("Gaming");

uni = chatterbot.nextLine();
if (uni.contains("University"))
System.out.println("Do you like uni?");
uni = chatterbot.nextLine();
if (uni.contains("Yes"))
System.out.println("Do you study one of SE CS or IT?");
else if (uni.contains("No"))
System.out.println("Do you study one of SE CS or IT?");
uni = chatterbot.nextLine();
if (uni.contains("Yes"))
System.out.println("That is really great!");
else if (uni.contains("No"))
System.out.println("That is not good!");
System.exit(0);


gaming = chatterbot.nextLine();
if (gaming.contains("Gaming"))
System.out.println("Do you like gaming?");
gaming = chatterbot.nextLine();
if (gaming.contains("Yes"))
System.out.println("What kind of games do you like to play?");


I expect the output to be if the user types Uni then it says "Do you like uni?" and when you type gaming it says "Do you like gaming?" The uni part works but when I type Gaming nothing appears.










share|improve this question
























  • Don't use new String("University"), just do String uni = "University";

    – GBlodgett
    Mar 23 at 23:53






  • 1





    Also remove the semicolon after the last if

    – GBlodgett
    Mar 24 at 0:00











  • No reason to use 2 different String fields for this. Just use String input = chatterbot.nextLine(); first time and use input = chatterbot.nextLine(); second time. No need to instantiate strings with University and Gaming values either.

    – oxyt
    Mar 24 at 0:03


















1















I need to include 10 variables but when I type in anything it comes up with only 1 of the variables I need to know how to make it so for example when "Gaming" is typed, the program comes back with "Do you like gaming?" right now it is at the point where anything I type it comes up with "Do you like uni?"



I have tried searching google for 3 hours and have done everything they have said and I can't find it. using .contains doesn't work for some reason.



 Scanner chatterbot = new Scanner(System.in); 
String uni = ("University");
String gaming = ("Gaming");

uni = chatterbot.nextLine();
if (uni.contains("University"))
System.out.println("Do you like uni?");
uni = chatterbot.nextLine();
if (uni.contains("Yes"))
System.out.println("Do you study one of SE CS or IT?");
else if (uni.contains("No"))
System.out.println("Do you study one of SE CS or IT?");
uni = chatterbot.nextLine();
if (uni.contains("Yes"))
System.out.println("That is really great!");
else if (uni.contains("No"))
System.out.println("That is not good!");
System.exit(0);


gaming = chatterbot.nextLine();
if (gaming.contains("Gaming"))
System.out.println("Do you like gaming?");
gaming = chatterbot.nextLine();
if (gaming.contains("Yes"))
System.out.println("What kind of games do you like to play?");


I expect the output to be if the user types Uni then it says "Do you like uni?" and when you type gaming it says "Do you like gaming?" The uni part works but when I type Gaming nothing appears.










share|improve this question
























  • Don't use new String("University"), just do String uni = "University";

    – GBlodgett
    Mar 23 at 23:53






  • 1





    Also remove the semicolon after the last if

    – GBlodgett
    Mar 24 at 0:00











  • No reason to use 2 different String fields for this. Just use String input = chatterbot.nextLine(); first time and use input = chatterbot.nextLine(); second time. No need to instantiate strings with University and Gaming values either.

    – oxyt
    Mar 24 at 0:03














1












1








1








I need to include 10 variables but when I type in anything it comes up with only 1 of the variables I need to know how to make it so for example when "Gaming" is typed, the program comes back with "Do you like gaming?" right now it is at the point where anything I type it comes up with "Do you like uni?"



I have tried searching google for 3 hours and have done everything they have said and I can't find it. using .contains doesn't work for some reason.



 Scanner chatterbot = new Scanner(System.in); 
String uni = ("University");
String gaming = ("Gaming");

uni = chatterbot.nextLine();
if (uni.contains("University"))
System.out.println("Do you like uni?");
uni = chatterbot.nextLine();
if (uni.contains("Yes"))
System.out.println("Do you study one of SE CS or IT?");
else if (uni.contains("No"))
System.out.println("Do you study one of SE CS or IT?");
uni = chatterbot.nextLine();
if (uni.contains("Yes"))
System.out.println("That is really great!");
else if (uni.contains("No"))
System.out.println("That is not good!");
System.exit(0);


gaming = chatterbot.nextLine();
if (gaming.contains("Gaming"))
System.out.println("Do you like gaming?");
gaming = chatterbot.nextLine();
if (gaming.contains("Yes"))
System.out.println("What kind of games do you like to play?");


I expect the output to be if the user types Uni then it says "Do you like uni?" and when you type gaming it says "Do you like gaming?" The uni part works but when I type Gaming nothing appears.










share|improve this question
















I need to include 10 variables but when I type in anything it comes up with only 1 of the variables I need to know how to make it so for example when "Gaming" is typed, the program comes back with "Do you like gaming?" right now it is at the point where anything I type it comes up with "Do you like uni?"



I have tried searching google for 3 hours and have done everything they have said and I can't find it. using .contains doesn't work for some reason.



 Scanner chatterbot = new Scanner(System.in); 
String uni = ("University");
String gaming = ("Gaming");

uni = chatterbot.nextLine();
if (uni.contains("University"))
System.out.println("Do you like uni?");
uni = chatterbot.nextLine();
if (uni.contains("Yes"))
System.out.println("Do you study one of SE CS or IT?");
else if (uni.contains("No"))
System.out.println("Do you study one of SE CS or IT?");
uni = chatterbot.nextLine();
if (uni.contains("Yes"))
System.out.println("That is really great!");
else if (uni.contains("No"))
System.out.println("That is not good!");
System.exit(0);


gaming = chatterbot.nextLine();
if (gaming.contains("Gaming"))
System.out.println("Do you like gaming?");
gaming = chatterbot.nextLine();
if (gaming.contains("Yes"))
System.out.println("What kind of games do you like to play?");


I expect the output to be if the user types Uni then it says "Do you like uni?" and when you type gaming it says "Do you like gaming?" The uni part works but when I type Gaming nothing appears.







java






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 24 at 10:07







Fidelity

















asked Mar 23 at 23:35









FidelityFidelity

62




62












  • Don't use new String("University"), just do String uni = "University";

    – GBlodgett
    Mar 23 at 23:53






  • 1





    Also remove the semicolon after the last if

    – GBlodgett
    Mar 24 at 0:00











  • No reason to use 2 different String fields for this. Just use String input = chatterbot.nextLine(); first time and use input = chatterbot.nextLine(); second time. No need to instantiate strings with University and Gaming values either.

    – oxyt
    Mar 24 at 0:03


















  • Don't use new String("University"), just do String uni = "University";

    – GBlodgett
    Mar 23 at 23:53






  • 1





    Also remove the semicolon after the last if

    – GBlodgett
    Mar 24 at 0:00











  • No reason to use 2 different String fields for this. Just use String input = chatterbot.nextLine(); first time and use input = chatterbot.nextLine(); second time. No need to instantiate strings with University and Gaming values either.

    – oxyt
    Mar 24 at 0:03

















Don't use new String("University"), just do String uni = "University";

– GBlodgett
Mar 23 at 23:53





Don't use new String("University"), just do String uni = "University";

– GBlodgett
Mar 23 at 23:53




1




1





Also remove the semicolon after the last if

– GBlodgett
Mar 24 at 0:00





Also remove the semicolon after the last if

– GBlodgett
Mar 24 at 0:00













No reason to use 2 different String fields for this. Just use String input = chatterbot.nextLine(); first time and use input = chatterbot.nextLine(); second time. No need to instantiate strings with University and Gaming values either.

– oxyt
Mar 24 at 0:03






No reason to use 2 different String fields for this. Just use String input = chatterbot.nextLine(); first time and use input = chatterbot.nextLine(); second time. No need to instantiate strings with University and Gaming values either.

– oxyt
Mar 24 at 0:03













1 Answer
1






active

oldest

votes


















1














When you call chatterbot.nextLine() your input is consumed so if you call nextLine() again it waits for the next input.
But by saving the input in a variable you can compare it to more than one value.



This should work:



Scanner chatterbot = new Scanner(System.in); 
String input = chatterbot.nextLine();
if (input.contains("University"))
System.out.println("Do you like uni?");
else if (input.contains("Gaming"))
System.out.println("Do you like gaming?");






share|improve this answer























  • I need to be able to add multiple answers for questions.

    – Fidelity
    Mar 24 at 1:10











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55319368%2fcreating-scanner-with-multiple-words%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














When you call chatterbot.nextLine() your input is consumed so if you call nextLine() again it waits for the next input.
But by saving the input in a variable you can compare it to more than one value.



This should work:



Scanner chatterbot = new Scanner(System.in); 
String input = chatterbot.nextLine();
if (input.contains("University"))
System.out.println("Do you like uni?");
else if (input.contains("Gaming"))
System.out.println("Do you like gaming?");






share|improve this answer























  • I need to be able to add multiple answers for questions.

    – Fidelity
    Mar 24 at 1:10















1














When you call chatterbot.nextLine() your input is consumed so if you call nextLine() again it waits for the next input.
But by saving the input in a variable you can compare it to more than one value.



This should work:



Scanner chatterbot = new Scanner(System.in); 
String input = chatterbot.nextLine();
if (input.contains("University"))
System.out.println("Do you like uni?");
else if (input.contains("Gaming"))
System.out.println("Do you like gaming?");






share|improve this answer























  • I need to be able to add multiple answers for questions.

    – Fidelity
    Mar 24 at 1:10













1












1








1







When you call chatterbot.nextLine() your input is consumed so if you call nextLine() again it waits for the next input.
But by saving the input in a variable you can compare it to more than one value.



This should work:



Scanner chatterbot = new Scanner(System.in); 
String input = chatterbot.nextLine();
if (input.contains("University"))
System.out.println("Do you like uni?");
else if (input.contains("Gaming"))
System.out.println("Do you like gaming?");






share|improve this answer













When you call chatterbot.nextLine() your input is consumed so if you call nextLine() again it waits for the next input.
But by saving the input in a variable you can compare it to more than one value.



This should work:



Scanner chatterbot = new Scanner(System.in); 
String input = chatterbot.nextLine();
if (input.contains("University"))
System.out.println("Do you like uni?");
else if (input.contains("Gaming"))
System.out.println("Do you like gaming?");







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 24 at 0:12









BahmutBahmut

111




111












  • I need to be able to add multiple answers for questions.

    – Fidelity
    Mar 24 at 1:10

















  • I need to be able to add multiple answers for questions.

    – Fidelity
    Mar 24 at 1:10
















I need to be able to add multiple answers for questions.

– Fidelity
Mar 24 at 1:10





I need to be able to add multiple answers for questions.

– Fidelity
Mar 24 at 1:10



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55319368%2fcreating-scanner-with-multiple-words%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현