写一个函数,求一个字符串的长度,在main函数中输入字符串,并输出其长度. public class Example39 { public static void main(String[] args) { length("Hello World!"); } public static void length(String s) { int n = s.length(); System.out.println("输入的字符…
有n个人围成一圈,顺序排号.从第一个人开始报数(从1到3报数),凡报到3的人退出圈子,问最后留下的是原来第几号的那位. public class Example37 { public static void main(String[] args) { f(1000); } public static void f(int n) { boolean[] arr = new boolean[n]; for (int i = 0; i < arr.…
输入3个数a,b,c,按大小顺序输出. public class Example34 { public static void main(String[] args) { sort(5, 20, 15); } public static void sort(int a, int b, int c) { if (a < b) { int t = a; a = b; b = t; …
取一个整数a从右端开始的4-7位. public class Example32 { public static void main(String[] args) { cut(123456789); } public static void cut(long n) { String s = Long.toString(n); char[] c = s.toCharArray(); int j = c.length; …
将一个数组逆序输出. public class Example31 { public static void main(String[] args) { int[] a = { 9, 4, 6, 8, 3, 21, 16, 12 }; covertArray(a); } public static void covertArray(int[] a) { System.out.print("原数组为:"); for (i…