Results 1 to 7 of 7
  1. #1
    mmirbekian is offline Member
    Join Date
    Jul 2016
    Posts
    17
    Rep Power
    0

    Default Printing equal pairs from an array

    I have a code (got it from someone else) \ that only shows duplicate numbers in an input but I wanna change it so it would:
    input: Your number: 1221
    print: numbers: you have two pairs: numbers 1 and 2 are your pairs.
    Enter another number: 1223
    print: you have one pair: number 2 is your pair.

    Java Code:
    public class DuplicateNum {
    	 public static void main(String[] args) {
    		 System.out.println("Please enter a number: "); 
    		 System.out.println("Duplicates: " + Arrays.stream(String.valueOf(new Scanner(System.in).next()).split("")).map(Integer::valueOf).collect(Collectors.groupingBy(Function.identity(), Collectors.counting())).entrySet().stream().filter(e -> e.getValue() > 1).map(Map.Entry::getKey).collect(Collectors.toList()));
    	          
    	     }
    	 }
    Last edited by mmirbekian; 07-29-2016 at 08:38 PM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Printing equal pairs from an array

    I wanna change it
    Ok, what have you tried? What problems are you having?
    Post the new code showing what you have tried and ask some questions about the problems.

    Note: Chaining all those methods together makes the code hard to read, understand and debug.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    mmirbekian is offline Member
    Join Date
    Jul 2016
    Posts
    17
    Rep Power
    0

    Default Re: Printing equal pairs from an array

    Quote Originally Posted by Norm View Post
    Ok, what have you tried? What problems are you having?
    Post the new code showing what you have tried and ask some questions about the problems.

    Note: Chaining all those methods together makes the code hard to read, understand and debug.
    I have been researching about these methods but I don't know how to assemble these if I were to write a new one..beginner..I'm trying to go through each single method right now..Thanks

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Printing equal pairs from an array

    I recommend you first read the tutorials and understand both lambda constructs and method references

    Then check out the section on aggregate operations.

    You should have the API handy so you can see the various ways of constructing these types of statements.

    And it also helps to have a decent understanding of generics.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  5. #5
    mmirbekian is offline Member
    Join Date
    Jul 2016
    Posts
    17
    Rep Power
    0

    Default Re: Printing equal pairs from an array

    Quote Originally Posted by jim829 View Post
    I recommend you first read the tutorials and understand both lambda constructs and method references

    Then check out the section on aggregate operations.

    You should have the API handy so you can see the various ways of constructing these types of statements.

    And it also helps to have a decent understanding of generics.

    Regards,
    Jim
    Thanks alot for helping me.. Every time I open java APIs, I get confused. Where to begin reading? I get lost. But I'll do my best and reading as much as books as possible..

  6. #6
    mmirbekian is offline Member
    Join Date
    Jul 2016
    Posts
    17
    Rep Power
    0

    Default Re: Printing equal pairs from an array

    Quote Originally Posted by mmirbekian View Post
    Thanks alot for helping me.. Every time I open java APIs, I get confused. Where to begin reading? I get lost. But I'll do my best and reading as much as books as possible..
    I'm home schooling until I can get into a java class.

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    26

    Default Re: Printing equal pairs from an array

    Quote Originally Posted by mmirbekian View Post
    Where to begin reading?
    Quote Originally Posted by jim829 View Post
    I recommend you first read the tutorials and understand both lambda constructs and method references

    Then check out the section on aggregate operations.
    Nuff said.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Sort through array, finding pairs.
    By Wnt2bsleepin in forum New To Java
    Replies: 25
    Last Post: 02-08-2012, 03:29 AM
  2. checking array items are equal
    By trishtren in forum New To Java
    Replies: 5
    Last Post: 10-16-2011, 12:23 PM
  3. Printing an Array
    By overlordjebus in forum Java Applets
    Replies: 9
    Last Post: 04-14-2010, 02:26 AM
  4. Array length and printing out uninitialized array.
    By nicolek808 in forum New To Java
    Replies: 4
    Last Post: 09-10-2009, 09:12 AM
  5. printing array
    By mayhewj7 in forum New To Java
    Replies: 6
    Last Post: 02-12-2009, 02:01 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
  •