Page 2 of 2 FirstFirst 12
Results 21 to 30 of 30
  1. #21
    backdown is offline Member
    Join Date
    Jan 2011
    Posts
    12
    Rep Power
    0

    Default

    You can believe whichever you want, but i am not trying to cheat/am not lying. I am just trying to learn, and the easiest way to do it is if someone shows me the code, and i can manipulate it.

  2. #22
    backdown is offline Member
    Join Date
    Jan 2011
    Posts
    12
    Rep Power
    0

    Default

    I have everything i need to do now, besides declaring what String month, day, year; are, and the locations of them?

    This is what i have so far :

    Java Code:
    import java.util.Scanner;
    //This program does math
    public class Final
    {
    		public static void main(String []args)
    		{
    			Scanner in=new Scanner(System.in);
    			System.out.println("One last test");
    
    			System.out.print("Enter your birthday (mm/dd/yyyy): ");
    
    			String roar=in.nextLine();
    			int n1=Integer.parseInt(roar);
    
    			String date;
    			String month, day, year;
    			
    			System.out.println("You were born on" + month + "/" + day + "/" + year);
    
    		}
    	}

  3. #23
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default

    Wow, even after being spoonfed you still haven't a clue.
    Java Code:
    String roar=in.nextLine();
    int n1=Integer.parseInt(roar);
    Good luck with that!

  4. #24
    JavaHater is offline Senior Member
    Join Date
    Dec 2010
    Posts
    165
    Rep Power
    4

    Default

    Quote Originally Posted by sunde887 View Post
    Then you would use scanner.nextline() to store the input in some variable, and use a string tokenizer to split it up.
    Java Code:
    //create a string tokenizer object
    StringTokenizer st = new StringTokenizer{date, "/");
    a split is good enough. besides StringTokenizer is outdated.

  5. #25
    backdown is offline Member
    Join Date
    Jan 2011
    Posts
    12
    Rep Power
    0

    Default

    Because that line of code already exists in there..i dont see why it would go in again?

  6. #26
    JavaHater is offline Senior Member
    Join Date
    Dec 2010
    Posts
    165
    Rep Power
    4

    Default

    Quote Originally Posted by Junky View Post
    Where would we be without a bit of spoonfeeding?
    Everyone who post here , besides the OP, are all spoonfeeding in a way. Once you answer the OP, whether its a link pointing to some other places, whether its an example, whether its a concept, whether its a theory, ITS ALL SPOONFEEDING. What makes you think you are not spoonfeeding as well? The only time you are not spoon feeding is when you don't answer anything.

  7. #27
    JavaHater is offline Senior Member
    Join Date
    Dec 2010
    Posts
    165
    Rep Power
    4

    Default

    Quote Originally Posted by backdown View Post
    Because that line of code already exists in there..i dont see why it would go in again?
    did you see my example? Use the split() method, the returned array will contain the fields you want.

  8. #28
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default

    I call given people the code spoonfeeding as it does not make them go away and learn for themselves. I have seen on many occassions where someone has just copied and pasted the supplied code snippet directly into there code (this thread is a case in point) and then wondered why it doesn't work. Why? because they never took the time to try and understand what the code is doing. All they want is for the code to do what it should.

    If all you did was mention String.split and maybe provide the link to the API and then OP went away, read about it and wrote a bit of code to test their understanding, this is learning and 1000 times better than just giving them a code dump.

    My 0.02cents

  9. #29
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Oh wow, learned something new, stringtokenizer is outdated, since the op went with that instead of using split I will explain though.

    op:
    create a stringtokenizer object after storing the input in a string, set the string tokenizer object to work on the date string and "/"
    Java Code:
    StringTokenizer st = new StringTokenizer(date, "/");
    then set variables to nexttoken
    Java Code:
    String month = st.nextToken();
    String day = st.nextToken();
    String year = st.nextToken();
    Someone gave you code which uses split and a for:each loop, you can easily change that to a regular for loop
    Java Code:
    System.out.print("Your birth date is ");
    for(int i = 0; i < s.length; i++){
      if(i == (s.length - 1)){
        System.out.print(s[i]);
      }
      else{
        System.out.print(s[i] + "/");
      }
    }

  10. #30
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Basic GUI help
    By vahshir in forum New To Java
    Replies: 5
    Last Post: 10-11-2010, 01:33 AM
  2. Need really basic help!
    By anthonyalaan in forum New To Java
    Replies: 9
    Last Post: 09-12-2010, 01:43 PM
  3. Basic Help
    By robjames in forum New To Java
    Replies: 3
    Last Post: 02-09-2009, 02:58 AM
  4. Need some really basic help
    By Mayur in forum New To Java
    Replies: 6
    Last Post: 01-24-2009, 06:00 AM
  5. help with basic example
    By fred in forum New To Java
    Replies: 1
    Last Post: 07-20-2007, 05:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •