public class TestNumber {
static int x;
public static void main(String[] args) {
/*
*判断值6位置,左右相加的和相等
*/
String z = “1->2->3->4->5”;//5->4->3->2->1
StringBuffer sb = new StringBuffer(z).reverse();
String ss = sb.toString().replaceAll(">-", “->”);
System.out.println("ss = " + ss);
int[] ints = {1, 2, 3, 4, 6, 4, 3, 2, 1};
int sum1 = 0, sum2 = 0;
for (int i = 0, j = ints.length - 1; j > 0; i++, j--) {
if ((sum1 += ints[i]) == (sum2 += ints[j])) {
x = (i + j) / 2;
} else {
return;
}
}
System.out.println("值在第" + (x + 1) + "位");
/*
*判断String字符串长度
* */
String s1 = "12345";
String s2 = "12345xx";
System.out.println("s2 = " + new TestNumber().getLength(s1, s2));
}
public String getLength(String s1, String s2) {
char[] c1 = s1.toCharArray();
char[] c2 = s2.toCharArray();
if (c2.length > c1.length) {
return s2;
}
return s1;
}
}