Page 2 of 2 First 12
  • Jump to page:
    #16
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2009
    Posts
    245
    Rep Power
    240
    sunvsunv, what we have here is a classic example of a help vampire. This is not the first one you have just given the answer to. This helps no one, least of all the person asking the questions. Please stop.

    Comments on this post

    • tfecw agrees : Great term!
    • codeJ agrees : i go with tfecw
  2. #17
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    1
    Rep Power
    0

    Thank you!


    Your code really helped me understand this.






    Originally Posted by spyder0101
    Hello and welcome to Devshed. First off, in the future please use code tags or the syntax highlighter . It makes any code you post much easier to read, which in turn will get you more help, and faster help. (shown below)

    With regards to your problem, you should be treating it like any other bug:

    1. Identify the bug. In this case, you correctly identified that the first word is always returned. The question then becomes, why. To most of us based on the responses the answer is obvious, however that does not help you for the rest of the semester (or career) if you can't understand how we see that. To properly identify a bug in a program this simple, grab a pen and paper (a debugger is the subject for a book, not a forum post ) and follow each step in your program writing out exactly what the code says to do, NOT what you know or think it should do. Some relevant places to get information about what is actually happening are the API docs and online tutorials. The API docs are the best source, especially in the long run since almost everything will have the same style documentation (you hope).

    2. Once the bug is identified, figure out what has to be changed for it to work and implement that change after backing up your current work. Otherwise you could introduce new bugs without an easy way to roll back the changes.

    3. Once you think the bug is fixed, test to confirm it is truly fixed by running several set of data through it to confirm it always works.

    Let us know when and how you solved it so we can offer additional advice if necessary or ask for more help if you need it.

    java Code:
    import java.util.*;
     
    public class longword
    {
    	static Scanner console = new Scanner(System.in);
    	public static void main(String[] args)
    	{
    		String word;
    		String longest = "";
     
    		System.out.print("Enter sentence: ");
    		word = console.next();
    		System.out.println();
     
    		if (word.length() > longest.length())
    		{
    			longest = word;
    			System.out.print("The longest word was: " + longest);
    		}
    	}
    }
Page 2 of 2 First 12
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo