I also forgot to tell you that the first "System.out.print(p[i]);" could
make a misleading output, so comment it out.

-- Amahdy
www.amahdy.net



On Mon, Oct 3, 2011 at 19:41, Amahdy <[email protected]> wrote:

> The only part of your code that's correct, is the swapping part, and
> actually if worked correct, will order your output decreasingly. Your code
> needs a lot or rework and readjustments but I'll try to help you with some
> comments, find them below.
>
> -- Amahdy
> www.amahdy.net
>
>
> On Mon, Oct 3, 2011 at 19:08, mandy <[email protected]> wrote:
>
>> here is my program and i want to return in sorting order.
>> input=42315
>> output=12345
>> and here is my program.......
>>
>>
>> public class Lottery
>> {
>>    static String str="42135";
>>    int ar[]=new int[20];
>>    int i=0,j=0,k=0;
>>    int temp=0;
>>    public int[] get(int[] p)
>>    {
>>        System.out.print(p[i]);
>>
>>        i++;
>>
> //Why? Remove it.
>
>>        if(i==str.length())
>>
> //Why? Remove it.
>
>>            for(j=0;j<str.length()-1;j++)
>>
> //Why length()-1? you have j< not j<= so you should not use -1
>
>>        {
>>            for(i=j+1;i<str.length();i++)
>>                if(p[j]<p[i])
>>
> //Swap this condition to get a correct increasing results
>
>>                {
>>                    temp=p[j];
>>                    p[j]=p[i];
>>                    p[i]=temp;
>>
>>                }
>>
>>        }
>>        //if(j==str.length())
>>          return p;
>>      }
>>    public static void main(String arg[])
>>    {
>>        Lottery ob=new Lottery();
>>
>>        int l=0;
>>        int a[]=new int[5];
>>        int j[]=new int[5];
>>        try
>>        {
>>        for(int i=0;i<a.length;i++)
>>        {
>>            a[i]=str.charAt(i)-'0';
>>
> //Now, here there is a lot of confusing code, so start by closing the first
> for loop here '}'
>
>>
>>        //for(l=0;l<a.length;l++)
>>
> //And activate this one but after the next line of code, because the coming
> line of code should be executed once and only once. Don't forget to add '{'
> to start the for loop body.
>
>>        j=ob.get(a);
>>         System.out.print(j[l]);
>>              l++;
>>
> //Why? Remove it.
>
>>        }
>>        }
>>        catch(Exception e)
>>    {
>>        System.out.println("got excep:"+e);
>>    }
>> }
>> }
>>
>
> --
>> You received this message because you are subscribed to the Google Groups
>> "google-codejam" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/google-code?hl=en.
>>
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"google-codejam" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-code?hl=en.

Reply via email to