Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #33535 > unrolled thread
| Started by | puja219@gmail.com |
|---|---|
| First post | 2016-01-26 09:15 -0800 |
| Last post | 2016-04-06 14:17 -0700 |
| Articles | 7 — 6 participants |
Back to article view | Back to comp.lang.java.programmer
pendulum program -7 number input not working puja219@gmail.com - 2016-01-26 09:15 -0800
Re: pendulum program -7 number input not working Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-01-26 13:11 -0500
Re: pendulum program -7 number input not working Jeff Higgins <jeff@invalid.invalid> - 2016-01-27 02:05 +0000
Re: pendulum program -7 number input not working Jeff Higgins <jeff@invalid.invalid> - 2016-01-27 02:11 +0000
Re: pendulum program -7 number input not working Arne Vajhøj <arne@vajhoej.dk> - 2016-01-26 21:39 -0500
Re: pendulum program -7 number input not working Lew <lewbloch@gmail.com> - 2016-01-27 15:08 -0800
Re: pendulum program -7 number input not working parthmadhani9@gmail.com - 2016-04-06 14:17 -0700
| From | puja219@gmail.com |
|---|---|
| Date | 2016-01-26 09:15 -0800 |
| Subject | pendulum program -7 number input not working |
| Message-ID | <7b9b4702-130f-4533-8c3c-3d39c1fd9f6a@googlegroups.com> |
import java.util.*;
class Pendulum_Sorting
{public static void main()
{ Scanner sc=new Scanner(System.in);
System.out.println("Enter the size of the array");
int n=sc.nextInt();
int a[]=new int[n];
System.out.println("Enter the elements of the array");
for(int i=0;i<n;i++)
a[i]=sc.nextInt();
int mid=0,min=0,l=0,pos=0;
for(int i=0;i<n;i++)
{if(i%2==0)
mid=n/2-l;
else
mid=n/2+l;
min=a[mid];
for(int j=0;j<n;j++)
{if(i%2==0)
{if((j>=mid)&&(j<=(mid+(l*2))))
continue;
}
else
{if((j<=mid)&&(j>=(mid-(l*2)+1)))
continue;
}
if(a[j]<min)
{min=a[j];
pos=j;
}
}
a[pos]=a[mid];
a[mid]=min;
if(i%2==0)
l++;
}
for(int i=0;i<n;i++)
System.out.print(a[i]+" ");
}
}
[toc] | [next] | [standalone]
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Date | 2016-01-26 13:11 -0500 |
| Message-ID | <n88cn8$6kv$2@dont-email.me> |
| In reply to | #33535 |
On 1/26/2016 12:15 PM, puja219@gmail.com wrote:
> import java.util.*;
> [...]
Same problem as your other post about hexadecimal and
decimal conversion: "Not working" is too vague. Give a fuller
description of the problem.
--
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM
[toc] | [prev] | [next] | [standalone]
| From | Jeff Higgins <jeff@invalid.invalid> |
|---|---|
| Date | 2016-01-27 02:05 +0000 |
| Message-ID | <n898l8$88o$2@dont-email.me> |
| In reply to | #33535 |
On Tue, 26 Jan 2016 09:15:33 -0800, puja219 wrote: Ditto for the article titled "Pendulum Arrangement of a list of Integers in an Array" Please read the Oracle article "Code Conventions for the Java Programming Language" on the web. Proper formatting and commenting will make learning and debugging much easier.
[toc] | [prev] | [next] | [standalone]
| From | Jeff Higgins <jeff@invalid.invalid> |
|---|---|
| Date | 2016-01-27 02:11 +0000 |
| Message-ID | <n8990t$hq5$1@dont-email.me> |
| In reply to | #33541 |
On Wed, 27 Jan 2016 02:05:28 +0000, Jeff Higgins wrote: > On Tue, 26 Jan 2016 09:15:33 -0800, puja219 wrote: > > Ditto for the article titled "Pendulum Arrangement of a list of Integers > in an Array" > > Please read the Oracle article "Code Conventions for the Java > Programming Language" > on the web. Oops. Looks like that has been deprecated. You might start with "Google Java Style". > > Proper formatting and commenting will make learning and debugging much > easier.
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2016-01-26 21:39 -0500 |
| Message-ID | <n89aks$17ps$1@gioia.aioe.org> |
| In reply to | #33542 |
On 1/26/2016 9:11 PM, Jeff Higgins wrote: > On Wed, 27 Jan 2016 02:05:28 +0000, Jeff Higgins wrote: >> Please read the Oracle article "Code Conventions for the Java >> Programming Language" >> on the web. > > Oops. Looks like that has been deprecated. Not deprecated. Oracle just made a note about it not having been updated and that the content *may* not be valid. But people are still using it. With some extrapolation for the language elements added in later Java versions. Arne
[toc] | [prev] | [next] | [standalone]
| From | Lew <lewbloch@gmail.com> |
|---|---|
| Date | 2016-01-27 15:08 -0800 |
| Message-ID | <2971b313-4405-4bcf-b704-b5e9c2dfb00f@googlegroups.com> |
| In reply to | #33542 |
On Tuesday, January 26, 2016 at 6:14:42 PM UTC-8, Jeff Higgins wrote: > On Wed, 27 Jan 2016 02:05:28 +0000, Jeff Higgins wrote: > > > On Tue, 26 Jan 2016 09:15:33 -0800, puja219 wrote: > > > > Ditto for the article titled "Pendulum Arrangement of a list of Integers > > in an Array" > > > > Please read the Oracle article "Code Conventions for the Java > > Programming Language" > > on the web. > > Oops. Looks like that has been deprecated. > You might start with "Google Java Style". Deprecated or not, it's still a great starting point. > > > > Proper formatting and commenting will make learning and debugging much > > easier.
[toc] | [prev] | [next] | [standalone]
| From | parthmadhani9@gmail.com |
|---|---|
| Date | 2016-04-06 14:17 -0700 |
| Message-ID | <eeaad8b0-69c9-4149-b73d-4e26aed00e3c@googlegroups.com> |
| In reply to | #33535 |
On Tuesday, January 26, 2016 at 10:46:01 PM UTC+5:30, puj...@gmail.com wrote:
> for(int i=0;i<n;i++)
> {if(i%2==0)
> mid=n/2-l;
> else
> mid=n/2+l;
> min=a[mid];
make it n-1
import java.util.*;
class Pendulum_Sorting
{public static void main()
{ Scanner sc=new Scanner(System.in);
System.out.println("Enter the size of the array");
int n=sc.nextInt();
int a[]=new int[n];
System.out.println("Enter the elements of the array");
for(int i=0;i<n;i++)
a[i]=sc.nextInt();
int mid=0,min=0,l=0,pos=0;
for(int i=0;i<n-1;i++)
{
if(i%2==0)
mid=(n/2-l);
else
mid=(n/2+l);
min=a[mid];
for(int j=0;j<n;j++)
{if(i%2==0)
{if((j>=mid)&&(j<=(mid+(l*2))))
continue;
}
else
{if((j<=mid)&&(j>=(mid-(l*2)+1)))
continue;
}
if(a[j]<min)
{min=a[j];
pos=j;
}
}
a[pos]=a[mid];
a[mid]=min;
if(i%2==0)
l++;
}
for(int i=0;i<n;i++)
System.out.print(a[i]+" ");
}
}
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web