在线等大神们为小弟解决一下简单的问题!!! 哪位大神能帮忙把一串数例如1,2,3,4,2,3,4,5,6,1,2,3,4,5,6,3,4,5,6,7.按拐点输出第一行输出1,2,3,4。第二行2,3,4,5,6。第三行1,2,3,4,5,6。第四行4,5,6,7谢谢大神的帮助啊!!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 int[20] a = {1,2,3,4,2,3,4,5,6,1,2,3,4,5,6,3,4,5,6,7};String str = a[0] + ",";for(int i = 0; i < 19 ; i++){ if( a[i] < a[i+1] ) { str += a[i+1] + ","; if( i == 18 ) System.out.println(str.length - 1); } else { System.out.println(str.length - 1); str = a[i+1]; } }这样写虽然笨一点,不过应该可以实现。你试试 应该可以实现int[20] a = {1,2,3,4,2,3,4,5,6,1,2,3,4,5,6,3,4,5,6,7};boolean flag = true;for(int i=0;i<a.length;i++){System.out.print(a[i]+" ");if(a[i]<a[i+1]flag=false;if(flag==flase){System.out.println("");flag = true;}} 反了int[20] a = {1,2,3,4,2,3,4,5,6,1,2,3,4,5,6,3,4,5,6,7};boolean flag = true;for(int i=0;i<a.length;i++){System.out.print(a[i]+" ");if(a[i]>a[i+1]flag=false;if(flag==flase){System.out.println("");flag = true;}} 运行结果:1 2 3 4 2 3 4 5 6 1 2 3 4 5 6 3 4 5 6 代码:package www.ygpt.org;/** 阳光平台 www.ygpt.org */public class Ygpt { public static void main(String[] args) { int[] a = { 1, 2, 3, 4, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 3, 4, 5, 6, 7 }; boolean flag = false; for (int i = 0; i < a.length - 1; i++) { System.out.print(a[i] + " "); if (a[i] > a[i + 1]) flag = true; if (flag) { System.out.println(""); flag = false; } } }}以上代码,已上机调试运行通过。 int[] s={那串数字};for(int i=1:i<s.length;i++){if(s[i]>=s[i-1]){System.out.print(s[i]);}else{System.out.println(s[i]);}} 8楼标记,呵呵 int[] a = {1, 2, 3, 4, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 3, 4, 5, 6, 7}; for (int i = 0; i < a.length - 1; i++) { System.out.print(a[i]); if (a[i] + 1 != a[i + 1]) { System.out.println(); } } 楼上都说过了..我就不贴代码了..基本就是for if int[] a = new int[]{1, 2, 3, 4, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 3, 4, 5, 6, 7}; for (int i = 1; i < a.length; i++) { System.out.print(a[i - 1] + ((a[i - 1] > a[i]) ? ",\r\n" : ", ")); } System.out.print(a[a.length - 1]); public class GuanDian { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub int []arr={1,2,3,4,2,3,4,5,6,1,2,3,4,5,6,3,4,5,6}; boolean result=true; for (int i = 0; i < arr.length-1; i++) { System.out.print(arr[i]+","); if(arr[i]>arr[i+1]) result=true; else result=false; } }}在控制台输出的是:1,2,3,4,2,3,4,5,6,1,2,3,4,5,6,3,4,5,怎么少一个6??? int[] s = { 1, 2, 3, 4, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 3, 4, 5, 6, 7 }; for (int i = 1; i < s.length; i++) { if (s[i] >= s[i - 1]) { System.out.print(s[i - 1]); } else { System.out.println(s[i - 1]); } } JAVA的堆内存 大神帮忙看下是什么原因,表单提交不了 加载ibatis文件报错,大侠指点!! JAVA技术交流 struts2中的路径问题 jsp页面加载 首页显示数据库里的数据的问题 急求jsp+javamail带附件发送邮件的源码. .....高分 怎样用javamail发送html? 苦恼中,用jbuilder+weblogic部署ejb有的时候成功,有的时候出错,不知道错在哪里,请高手教教菜鸟(错误代码如下) 求介绍一本java web项目实例的书籍 java字符串操作
String str = a[0] + ",";
for(int i = 0; i < 19 ; i++){
if( a[i] < a[i+1] ) {
str += a[i+1] + ",";
if( i == 18 )
System.out.println(str.length - 1);
} else {
System.out.println(str.length - 1);
str = a[i+1];
}
}这样写虽然笨一点,不过应该可以实现。你试试
int[20] a = {1,2,3,4,2,3,4,5,6,1,2,3,4,5,6,3,4,5,6,7};
boolean flag = true;
for(int i=0;i<a.length;i++)
{
System.out.print(a[i]+" ");
if(a[i]<a[i+1]
flag=false;
if(flag==flase)
{
System.out.println("");
flag = true;
}
}
int[20] a = {1,2,3,4,2,3,4,5,6,1,2,3,4,5,6,3,4,5,6,7};
boolean flag = true;
for(int i=0;i<a.length;i++)
{
System.out.print(a[i]+" ");
if(a[i]>a[i+1]
flag=false;
if(flag==flase)
{
System.out.println("");
flag = true;
}
}
1 2 3 4
2 3 4 5 6
1 2 3 4 5 6
3 4 5 6 代码:
package www.ygpt.org;/** 阳光平台 www.ygpt.org */
public class Ygpt {
public static void main(String[] args) {
int[] a = { 1, 2, 3, 4, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 3, 4, 5, 6, 7 };
boolean flag = false;
for (int i = 0; i < a.length - 1; i++) {
System.out.print(a[i] + " ");
if (a[i] > a[i + 1])
flag = true;
if (flag) {
System.out.println("");
flag = false;
}
}
}
}以上代码,已上机调试运行通过。
for(int i=1:i<s.length;i++){
if(s[i]>=s[i-1]){
System.out.print(s[i]);
}else{
System.out.println(s[i]);
}
}
int[] a = {1, 2, 3, 4, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 3, 4, 5, 6, 7};
for (int i = 0; i < a.length - 1; i++)
{
System.out.print(a[i]);
if (a[i] + 1 != a[i + 1])
{
System.out.println();
}
}
int[] a = new int[]{1, 2, 3, 4, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 3, 4, 5, 6, 7};
for (int i = 1; i < a.length; i++) {
System.out.print(a[i - 1] + ((a[i - 1] > a[i]) ? ",\r\n" : ", "));
}
System.out.print(a[a.length - 1]);
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub int []arr={1,2,3,4,2,3,4,5,6,1,2,3,4,5,6,3,4,5,6};
boolean result=true;
for (int i = 0; i < arr.length-1; i++) {
System.out.print(arr[i]+",");
if(arr[i]>arr[i+1])
result=true;
else
result=false;
}
}
}
在控制台输出的是:1,2,3,4,2,3,4,5,6,1,2,3,4,5,6,3,4,5,怎么少一个6???
for (int i = 1; i < s.length; i++) {
if (s[i] >= s[i - 1]) {
System.out.print(s[i - 1]);
} else {
System.out.println(s[i - 1]);
}
}