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: Can anybody explain this code in details

  1. #1
    Member
    Join Date
    Sep 2012
    Posts
    45
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Can anybody explain this code in details

    Hello,
    Can anybody explain each lines of this code in details? I understand most of it, but I have a couple of problems with some of the logic and coding.

    class Josephus
    {
        static class Node
          { int val; Node next;
            Node(int v) { val = v; }
          }
        public static void main(String[] args)
          { int N = Integer.parseInt(args[0]);
            int M = Integer.parseInt(args[1]);
            Node t = new Node(1);
            Node x = t;
            for (int i = 2; i <= N; i++)
              x = (x.next = new Node(i));
            x.next = t;
            while (x != x.next)
              {
                for (int i = 1; i < M; i++) x = x.next;
                x.next = x.next.next;
              }
            Out.println("Survivor is " + x.val);
          }
      }


  2. #2
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    987
    Thanks
    6
    Thanked 206 Times in 182 Posts

    Default Re: Can anybody explain this code in details

    So, what are the problems? And what is the code supposed to do?

    And does the code compile? Hint: no, it doesn't. The compiler grumbles about Out. So, what is that all about?

    Sorry about all the questions, but it strikes me that the road to understanding isn't so much sign posted as punctuated by questioning billboards. And Josephus rocks! Although what a 0-th century historian and general was thinking about posing questions of number theory, baffles me.[COLOR="Silver"]

    ---

Similar Threads

  1. Can someone please explain this code for me?
    By Grot in forum What's Wrong With My Code?
    Replies: 9
    Last Post: January 17th, 2013, 11:56 AM
  2. Could you explain this code to me please?
    By TP-Oreilly in forum Java Theory & Questions
    Replies: 8
    Last Post: December 7th, 2011, 02:10 PM
  3. Pls explain me the code logic
    By Shajith in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 25th, 2011, 02:41 AM
  4. Can anyone explain this code for me
    By gudwindavids in forum Object Oriented Programming
    Replies: 1
    Last Post: December 11th, 2009, 02:29 PM
  5. Help me this code! Someone please explain strings!
    By helpthiscode in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 16th, 2009, 03:13 AM

Tags for this Thread