jkboy880826
BAN USERBubble sort, only a[i]>0&&a[i+1]<0 will exchange each other
Code:
public class HelloWorld{
public static void main(String []args){
int a[]={-1,3,5,-7,2,4,-6,8};
int len=a.length;
for(int i=0;i<len;i++)//bubble sort times
{
for(int j=0;j<len-1-i;j++)// times of comparison in each loop
{
if(a[j]>0&&a[j+1]<0)
{a[j]=a[j]-a[j+1];
a[j+1]=a[j]+a[j+1];
a[j]=a[j+1]-a[j];
}
}
}
for (int i=0;i<len;i++)
{
System.out.println(a[i]);
}
}
}
Bubble sort, only a[i]>0&&a[i+1]<0 will exchange each other
Code:
public class HelloWorld{
public static void main(String []args){
int a[]={-1,3,5,-7,2,4,-6,8};
int len=a.length;
for(int i=0;i<len;i++)//bubble sort times
{
for(int j=0;j<len-1-i;j++)// times of comparison in each loop
{
if(a[j]>0&&a[j+1]<0)
{a[j]=a[j]-a[j+1];
a[j+1]=a[j]+a[j+1];
a[j]=a[j+1]-a[j];
}
}
}
for (int i=0;i<len;i++)
{
System.out.println(a[i]);
}
}
}
Bubble sort, only a[i]>0&&a[i+1]<0 will exchange each other
Code:
public class HelloWorld{
public static void main(String []args){
int a[]={-1,3,5,-7,2,4,-6,8};
int len=a.length;
for(int i=0;i<len;i++)//bubble sort times
{
for(int j=0;j<len-1-i;j++)// times of comparison in each loop
{
if(a[j]>0&&a[j+1]<0)
{a[j]=a[j]-a[j+1];
a[j+1]=a[j]+a[j+1];
a[j]=a[j+1]-a[j];
}
}
}
for (int i=0;i<len;i++)
{
System.out.println(a[i]);
}
}
}
Bubble sort, only a[i]>0&&a[i+1]<0 will exchange each other
Code:
public class HelloWorld{
public static void main(String []args){
int a[]={-1,3,5,-7,2,4,-6,8};
int len=a.length;
for(int i=0;i<len;i++)//bubble sort times
{
for(int j=0;j<len-1-i;j++)// times of comparison in each loop
{
if(a[j]>0&&a[j+1]<0)
{a[j]=a[j]-a[j+1];
a[j+1]=a[j]+a[j+1];
a[j]=a[j+1]-a[j];
}
}
}
for (int i=0;i<len;i++)
{
System.out.println(a[i]);
}
}
}
Bubble sort, only a[i]>0&&a[i+1]<0 will exchange each other
Code:
public class HelloWorld{
public static void main(String []args){
int a[]={-1,3,5,-7,2,4,-6,8};
int len=a.length;
for(int i=0;i<len;i++)//bubble sort times
{
for(int j=0;j<len-1-i;j++)// times of comparison in each loop
{
if(a[j]>0&&a[j+1]<0)
{a[j]=a[j]-a[j+1];
a[j+1]=a[j]+a[j+1];
a[j]=a[j+1]-a[j];
}
}
}
for (int i=0;i<len;i++)
{
System.out.println(a[i]);
}
}
}
public class HelloWorld{
public static void main(String []args){
String test="mestts,youoygg,mesccsem";
int len=test.length();
char[] strtest=new char[len];
int maxcount=0;
for(int i=0;i<len;i++)
{
char a=test.charAt(i);
strtest[i]=a;
}
if (len<2)
{
System.out.print(1);
}
else
{
for(int i=0;i<len;i++)//main char position,get char chain length
{
for (int j=1;j<=len-i;j++)//chains' length,j is length
{
char[] unit=new char[j];
for (int k=0;k<j;k++)//get string of the char chain
{
unit[k]=strtest[i+k];
}
String truetest=String.valueOf(unit);//string express;
int lenoftrue=truetest.length();
int lockt=0;
if(lenoftrue==1)
{
lockt=1;
}
else
{
for (int count=0;count<lenoftrue/2;count++)//for compare
{
if(truetest.charAt(count)==truetest.charAt(lenoftrue-count-1))
{
lockt=1;
continue;
}
else
{ lockt=0;
break;
}
}
}
if(lockt==1&&lenoftrue>=maxcount)
{
maxcount=lenoftrue;
}
}
}
System.out.print(maxcount);
}
}
}
public class HelloWorld{
public static void main(String []args){
String test="mestts,youoygg,mesccsem";
int len=test.length();
char[] strtest=new char[len];
int maxcount=0;
for(int i=0;i<len;i++)
{
char a=test.charAt(i);
strtest[i]=a;
}
if (len<2)
{
System.out.print(1);
}
else
{
for(int i=0;i<len;i++)//main char position,get char chain length
{
for (int j=1;j<=len-i;j++)//chains' length,j is length
{
char[] unit=new char[j];
for (int k=0;k<j;k++)//get string of the char chain
{
unit[k]=strtest[i+k];
}
String truetest=String.valueOf(unit);//string express;
int lenoftrue=truetest.length();
int lockt=0;
if(lenoftrue==1)
{
lockt=1;
}
else
{
for (int count=0;count<lenoftrue/2;count++)//for compare
{
if(truetest.charAt(count)==truetest.charAt(lenoftrue-count-1))
{
lockt=1;
continue;
}
else
{ lockt=0;
break;
}
}
}
if(lockt==1&&lenoftrue>=maxcount)
{
maxcount=lenoftrue;
}
}
}
System.out.print(maxcount);
}
}
}
Bubble sort, only a[i]>0&&a[i+1]<0 will exchange each other
Code:
- jkboy880826 August 05, 2014