Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: String input = keyboard.nextLine();

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post String input = keyboard.nextLine();

    import java.util.Scanner;
     
    public class beraknaTal {
     
    	public static void main(String[] args) {
    		Scanner keyboard = new Scanner(System.in);
     
     
    	int resultat, tal1, tal2;
     
     
    	System.out.print("Ange ett heltal: ");
    			tal1 = keyboard.nextInt();
    		System.out.print("Ange ett till heltal: ");
    			tal2 = keyboard.nextInt();
     
    	do{	
    		System.out.print(+tal1 + "+" +tal2 +"= ");
    		resultat = keyboard.nextInt();
    		}
     
    	while(resultat != tal1 + tal2);
     
                    System.out.println("You answered right, would you like to continue Yes or No ");
     
    		String input = keyboard.nextLine();
     
    		if (input.equals("No"))
    			System.out.println("Du behöver öva mer matematik");
    		if (input.equals("Yes"))
    			System.out.println("Då fortsätter vi då");

    Why isnt it possible to write yes or no in the console=/?


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: String input = keyboard.nextLine();

    Where does the code write that to the console? Are there any conditions that must be true like in an if statement or a while statement that will prevent the code from executing?
    If so, print out the values of the variables used in the condition so you can see what the program sees when it executes the statement with the condition.


    Can you copy the contents of the console and paste it here so we can see what you see when you execute the program?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Not prompting string user input.
    By Abhi01 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 8th, 2012, 10:26 PM
  2. How do i store input from the keyboard into a method?
    By javaStarter in forum Java Theory & Questions
    Replies: 2
    Last Post: December 23rd, 2011, 05:50 PM
  3. Multilingual keyboard input
    By yep in forum Java Theory & Questions
    Replies: 1
    Last Post: November 12th, 2011, 02:23 AM
  4. Taking Input in String Array
    By syehjafa in forum Collections and Generics
    Replies: 8
    Last Post: July 25th, 2011, 07:18 AM
  5. Reading String Input?
    By Morevan in forum Java Theory & Questions
    Replies: 1
    Last Post: January 18th, 2010, 12:16 PM