输入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; …
写一个函数,求一个字符串的长度,在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("输入的字符…
取一个整数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; …
求0~7所能组成的奇数个数.分析:组成1位数是4个,组成2位数是7*4个,组成3位数是7*8*4个,组成4位数是7*8*8*4个…… public class Example44 { public static void main(String[] args) { f(); } public static void f() { int sum = 4; int j; System.out.println("组成1位数是 &quo…
输入某年某月某日,判断这一天是这一年的第几天? public class Example14 { public static void main(String[] args) { year(2017, 1, 1); } public static void year(int year, int month, int day) { int d = 0; int days = 0; if (year < 0 || month <…
有五个学生,每个学生有3门课的成绩,从键盘输入以上数据(包括学生号,姓名,三门课成绩),计算出平均成绩,况原有的数据和计算出的平均分数存放在磁盘文件 "stud"中. public class Example50 { public static void main(String[] args) { stud(); } public static void stud() { Scanner ss = new Scanner(System.in); …