:D I'm completly new to Java and now I'm doing basic examples(with Java 1.7 and Eclipse IDE)
I have tried the code below.It should take user inputs an them display them in the end.
package loop;
import java.util.Scanner;
public class MainClass {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner user_input = new Scanner( System.in );
String name;
System.out.print("What is yout name?: ");
name = user_input.next();
String quest;
System.out.print("What is your quest?: ");
quest = user_input.next();
String color;
System.out.print("What is your favourite color?: ");
color = user_input.next();
String sentence;
sentence = "Your name is" + " " + name + " " + ",and your quest is" + " " + quest + " " + ",and your favourite color is" + " " + color;
System.out.println(sentence);
}
}
and everything thing works fine when I use only one word for input like here
What is yout name?: Marko
What is your quest?: seeking
What is your favourite color?: green
Your name is Marko ,and your quest is seeking ,and your favourite color is green
but everything fails with multiple words inputed:
What is yout name?: Marko Scekic
What is your quest?: What is your favourite color?: seeking blue
Your name is Marko ,and your quest is Scekic ,and your favourite color is seeking
What is yout name?: Marko
What is your quest?: seeking for Holy grail
What is your favourite color?: Your name is Marko ,and your quest is seeking ,and your favourite color is for
I tried everything that is in my power(I replaced print with println and reversed,tried changing the order of the questions etc..).