JAVA基础编程代码50个 |
您所在的位置:网站首页 › 简单代码制作视频大全 › JAVA基础编程代码50个 |
【程序1】 题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子对数为多少? 程序分析: 兔子的规律为数列1,1,2,3,5,8,13,21.... public class Prog1{ public static void main(String[] args){ int n = 10; System.out.println("第"+n+"个月兔子总数为"+fun(n)); } private static int fun(int n){ if(n==1 || n==2) return 1; else return fun(n-1)+fun(n-2); } } 【程序2】 题目:判断101-200之间有多少个素数,并输出所有素数。 程序分析:判断素数的方法:用一个数分别去除2到sqrt(这个数),如果能被整除,则表明此数不是素数,反之是素数。 public class Prog2{ public static void main(String[] args){ int m = 1; int n = 1000; int count = 0; //统计素数个数 for(int i=m;i count++; System.out.print(i+" "); if(count%10==0){ System.out.println(); } } } System.out.println(); System.out.println("在"+m+"和"+n+"之间共有"+count+"个素数"); } //判断素数 private static boolean isPrime(int n){ boolean flag = true; if(n==1) flag = false; else{ for(int i=2;i flag = false; break; } else flag = true; } } return flag; } } 【程序3】 题目:打印出所有的"水仙花数",所谓"水仙花数"是指一个三位数,其各位数字立方和等于该数本身。例如:153是一个"水仙花数",因为153=1的三次方+5的三次方+3的三次方。 程序分析:利用for循环控制100-999个数,每个数分解出个位,十位,百位。 public class Prog3{ public static void main(String[] args){ for(int i=100;i int m = 0; int n = lotus; int sum = 0; m = n/100; n -= m*100; sum = m*m*m; m = n/10; n -= m*10; sum += m*m*m + n*n*n; if(sum==lotus) return true; else return false; } } 【程序4】 题目:将一个正整数分解质因数。例如:输入90,打印出90=2*3*3*5。 程序分析:对n进行分解质因数,应先找到一个最小的质数k,然后按下述步骤完成: (1)如果这个质数恰等于n,则说明分解质因数的过程已经结束,打印出即可。 (2)如果nk,但n能被k整除,则应打印出k的值,并用n除以k的商,作为新的正整数n,重复执行第一步。 (3)如果n不能被k整除,则用k+1作为k的值,重复执行第一步。 public class Prog4{ public static void main(String[] args){ int n = 13; decompose(n); } private static void decompose(int n){ System.out.print(n+"="); for(int i=2;i n/=i; System.out.print(i+"*"); } if(n==i){ System.out.println(i); break; } } } } 【程序5】 题目:利用条件运算符的嵌套来完成此题:学习成绩>=90分的同学用A表示,60-89分之间的用B表示,60分以下的用C表示。 程序分析:(a>b)?a:b这是条件运算符的基本例子。 public class Prog5{ public static void main(String[] args){ int n = -1; try{ n = Integer.parseInt(args[0]); }catch(ArrayIndexOutOfBoundsException e){ System.out.println("请输入成绩"); return; } grade(n); } //成绩等级计算 private static void grade(int n){ if(n>100 || n public static void main(String[] args){ int m,n; try{ m = Integer.parseInt(args[0]); n = Integer.parseInt(args[1]); }catch(ArrayIndexOutOfBoundsException e){ System.out.println("输入有误"); return; } max_min(m,n); } //求最大公约数和最小公倍数 private static void max_min(int m, int n){ int temp = 1; int yshu = 1; int bshu = m*n; if(n temp = n%m; n = m; m = temp; } yshu = n; bshu /= n; System.out.println(m+"和"+n+"的最大公约数为"+yshu); System.out.println(m+"和"+n+"的最小公倍数为"+bshu); } } 【程序7】 题目:输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。 程序分析:利用while语句,条件为输入的字符不为'\n'. import java.util.Scanner; public class Prog7_1{ public static void main(String[] args){ System.out.print("请输入一串字符:"); Scanner scan = new Scanner(System.in); String str = scan.nextLine();//将一行字符转化为字符串 scan.close(); count(str); } //统计输入的字符数 private static void count(String str){ String E1 = "[\u4e00-\u9fa5]";//汉字 String E2 = "[a-zA-Z]"; String E3 = "[0-9]"; String E4 = "\\s";//空格 int countChinese = 0; int countLetter = 0; int countNumber = 0; int countSpace = 0; int countOther = 0; char[] array_Char = str.toCharArray();//将字符串转化为字符数组 String[] array_String = new String[array_Char.length];//汉字只能作为字符串处理 for(int i=0;i public static void main(String[] args){ System.out.println("请输入一行字符:"); Scanner scan = new Scanner(System.in); String str = scan.nextLine(); scan.close(); count(str); } //统计输入的字符 private static void count(String str){ List list = new ArrayList(); char[] array_Char = str.toCharArray(); for(char c:array_Char) list.add(String.valueOf(c));//将字符作为字符串添加到list表中 Collections.sort(list);//排序 for(String s:list){ int begin = list.indexOf(s); int end = list.lastIndexOf(s); //索引结束统计字符数 if(list.get(end)==s) System.out.println("字符‘"+s+"’有"+(end-begin+1)+"个"); } } } 【程序8】 题目:求s=a+aa+aaa+aaaa+aa...a的值,其中a是一个数字。例如2+22+222+2222+22222(此时共有5个数相加),几个数相加有键盘控制。 程序分析:关键是计算出每一项的值。 import java.util.Scanner;
public class Prog8{ public static void main(String[] args){ System.out.print("求s=a+aa+aaa+aaaa+...的值,请输入a的值:"); Scanner scan = new Scanner(System.in).useDelimiter("\\s*");//以空格作为分隔符 int a = scan.nextInt(); int n = scan.nextInt(); scan.close();//关闭扫描器 System.out.println(expressed(2,5)+add(2,5)); } //求和表达式 private static String expressed(int a,int n){ StringBuffer sb = new StringBuffer(); StringBuffer subSB = new StringBuffer(); for(int i=1;i long sum = 0; long subSUM = 0; for(int i=1;i public static void main(String[] args){ int n = 10000; compNumber(n); } //求完数 private static void compNumber(int n){ int count = 0; System.out.println(n+"以内的完数:"); for(int i=1;i if((i%j)==0){ sum += j; if(sum==i){ System.out.print(i+" "); if((count++)%5==0) System.out.println(); } } } } } } 【程序10】 题目:一球从100米高度自由落下,每次落地后反跳回原高度的一半;再落下,求它在第10次落地时,共经过多少米?第10次反弹多高? import java.util.Scanner; public class Prog10{ public static void main(String[] args){ System.out.print("请输入小球落地时的高度和求解的次数:"); Scanner scan = new Scanner(System.in).useDelimiter("\\s"); int h = scan.nextInt(); int n = scan.nextInt(); scan.close(); distance(h,n); } //小球从h高度落下,经n次反弹后经过的距离和反弹的高度 private static void distance(int h,int n){ double length = 0; for(int i=0;i public static void main(String[] args){ int count = 0; int n = 0; for(int i=1;i if(j==i) continue; for(int k=1;k n = i*100+j*10+k; System.out.print(n+" "); if((++count)%5==0) System.out.println(); } } } } System.out.println(); System.out.println("符合条件的数共:"+count+"个"); } } 【程序12】 题目:企业发放的奖金根据利润提成。利润(I)低于或等于10万元时,奖金可提10%;利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可可提成7.5%;20万到40万之间时,高于20万元的部分,可提成5%;40万到60万之间时高于40万元的部分,可提成3%;60万到100万之间时,高于60万元的部分,可提成1.5%,高于100万元时,超过100万元的部分按1%提成,从键盘输入当月利润I,求应发放奖金总数? 程序分析:请利用数轴来分界,定位。注意定义时需把奖金定义成长整型。 import java.io.*; public class Prog12{ public static void main(String[] args){ System.out.print("请输入当前利润:"); long profit = Long.parseLong(key_Input()); System.out.println("应发奖金:"+bonus(profit)); } //接受从键盘输入的内容 private static String key_Input(){ String str = null; BufferedReader bufIn = new BufferedReader(new InputStreamReader(System.in)); try{ str = bufIn.readLine(); }catch(IOException e){ e.printStackTrace(); }finally{ try{ bufIn.close(); }catch(IOException e){ e.printStackTrace(); } } return str; } //计算奖金 private static long bonus(long profit){ long prize = 0; long profit_sub = profit; if(profit>1000000){ profit = profit_sub-1000000; profit_sub = 1000000; prize += profit*0.01; } if(profit>600000){ profit = profit_sub-600000; profit_sub = 600000; prize += profit*0.015; } if(profit>400000){ profit = profit_sub-400000; profit_sub = 400000; prize += profit*0.03; } if(profit>200000){ profit = profit_sub-200000; profit_sub = 200000; prize += prize*0.05; } if(profit>100000){ profit = profit_sub-100000; profit_sub = 100000; prize += profit*0.075; } prize += profit_sub*0.1; return prize; } }
【程序13】 题目:一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少? 程序分析:在10万以内判断,先将该数加上100后再开方,再将该数加上268后再开方,如果开方后的结果满足如下条件,即是结果。 public class Prog13{ public static void main(String[] args){ int n=0; for(int i=0;i n = i; break; } } System.out.println("所求的数是:"+n); } //判断完全平方数 private static boolean isCompSqrt(int n){ boolean isComp = false; for(int i=1;i isComp = true; break; } } return isComp; } } 【程序14】 题目:输入某年某月某日,判断这一天是这一年的第几天? 程序分析:以3月5日为例,应该先把前两个月的加起来,然后再加上5天即本年的第几天,特殊情况,闰年且输入月份大于3时需考虑多加一天。 import java.util.Scanner; public class Prog14{ public static void main(String[] args){ Scanner scan = new Scanner(System.in).useDelimiter("\\D");//匹配非数字 System.out.print("请输入当前日期(年-月-日):"); int year = scan.nextInt(); int month = scan.nextInt(); int date = scan.nextInt(); scan.close(); System.out.println("今天是"+year+"年的第"+analysis(year,month,date)+"天"); } //判断天数 private static int analysis(int year, int month, int date){ int n = 0; int[] month_date = new int[] {0,31,28,31,30,31,30,31,31,30,31,30}; if((year%400)==0 || ((year%4)==0)&&((year%100)!=0)) month_date[2] = 29; for(int i=0;iy则将x与y的值进行交换,然后再用x与z进行比较,如果x>z则将x与z的值进行交换,这样能使x最小。 import java.util.Scanner; public class Prog15{ public static void main(String[] args){ Scanner scan = new Scanner(System.in).useDelimiter("\\D"); System.out.print("请输入三个数:"); int x = scan.nextInt(); int y = scan.nextInt(); int z = scan.nextInt(); scan.close(); System.out.println("排序结果:"+sort(x,y,z)); } //比较两个数的大小 private static String sort(int x,int y,int z){ String s = null; if(x>y){ int t = x; x = y; y = t; } if(x>z){ int t = x; x = z; z = t; } if(y>z){ int t = z; z = y; y = t; } s = x+" "+y+" "+z; return s; } } 【程序16】 题目:输出9*9口诀。 程序分析:分行与列考虑,共9行9列,i控制行,j控制列。 public class Prog16{ public static void main(String[] args){ for(int i=1;i public static void main(String[] args){ int m = 1; for(int i=10;i>0;i--) m = 2*m + 2; System.out.println("小猴子共摘了"+m+"桃子"); } } 【程序18】 题目:两个乒乓球队进行比赛,各出三人。甲队为a,b,c三人,乙队为x,y,z三人。已抽签决定比赛名单。有人向队员打听比赛的名单。a说他不和x比,c说他不和x,z比,请编程序找出三队赛手的名单。 import java.util.ArrayList; public class Prog18{ String a,b,c;//甲队成员 public static void main(String[] args){ String[] racer = {"x","y","z"};//乙队成员 ArrayList arrayList = new ArrayList(); for(int i=0;i this.a = a; this.b = b ; this.c = c; } public String toString(){ return "a的对手是"+a+" "+"b的对手是"+b+" "+"c的对手是"+c; } } 【程序19】 题目:打印出如下图案(菱形) * *** ****** ******** ****** *** * 程序分析:先把图形分成两部分来看待,前四行一个规律,后三行一个规律,利用双重 for循环,第一层控制行,第二层控制列。 public class Prog19{ public static void main(String[] args){ int n = 5; printStar(n); } //打印星星 private static void printStar(int n){ //打印上半部分 for(int i=0;i if(j=n-i && j if(j=i && j double n1 = 1; double n2 = 1; double fraction = n1/n2; double Sn = 0; for(int i=0;i public static void main(String[] args){ long sum = 0; for(int i=0;i public static void main(String[] args){ System.out.println(fact(10)); } //递归求阶乘 private static long fact(int n){ if(n==1) return 1; else return fact(n-1)*n; } } 【程序23】 题目:有5个人坐在一起,问第五个人多少岁?他说比第4个人大2岁。问第4个人岁数,他说比第3个人大2岁。问第三个人,又说比第2人大两岁。问第2个人,说比第一个人大两岁。最后问第一个人,他说是10岁。请问第五个人多大? 程序分析:利用递归的方法,递归分为回推和递推两个阶段。要想知道第五个人岁数,需知道第四人的岁数,依次类推,推到第一人(10岁),再往回推。 public class Prog23{ public static void main(String[] args){ System.out.println(getAge(5,2)); } //求第m位同志的年龄 private static int getAge(int m,int n){ if(m==1) return 10; else return getAge(m-1,n)+n; } } 【程序24】 题目:给一个不多于5位的正整数,要求:一、求它是几位数,二、逆序打印出各位数字。 public class Prog24{ public static void main(String[] args){ int n = Integer.parseInt(args[0]); int i = 0; int[] a = new int[5]; do{ a[i] = n%10; n /= 10; ++i; }while(n!=0); System.out.print("这是一个"+i+"位数,从个位起,各位数字依次为:"); for(int j=0;j int n = 0; System.out.print("请输入一个5位数:"); BufferedReader bufin = new BufferedReader(new InputStreamReader(System.in)); try{ n = Integer.parseInt(bufin.readLine()); }catch(IOException e){ e.printStackTrace(); }finally{ try{ bufin.close(); }catch(IOException e){ e.printStackTrace(); } } palin(n); } private static void palin(int n){ int m = n; int[] a = new int[5]; if(n99999){ System.out.println("输入的不是5位数!"); return; }else{ for(int i=0;i public static void main(String[] args){ String str = new String(); BufferedReader bufIn = new BufferedReader(new InputStreamReader(System.in)); System.out.print("请输入星期的英文单词前两至四个字母):"); try{ str = bufIn.readLine(); }catch(IOException e){ e.printStackTrace(); }finally{ try{ bufIn.close(); }catch(IOException e){ e.printStackTrace(); } } week(str); } private static void week(String str){ int n = -1; if(str.trim().equalsIgnoreCase("Mo") || str.trim().equalsIgnoreCase("Mon") || str.trim().equalsIgnoreCase("Mond")) n = 1; if(str.trim().equalsIgnoreCase("Tu") || str.trim().equalsIgnoreCase("Tue") || str.trim().equalsIgnoreCase("Tues")) n = 2; if(str.trim().equalsIgnoreCase("We") || str.trim().equalsIgnoreCase("Wed") || str.trim().equalsIgnoreCase("Wedn")) n = 3; if(str.trim().equalsIgnoreCase("Th") || str.trim().equalsIgnoreCase("Thu") || str.trim().equalsIgnoreCase("Thur")) n = 4; if(str.trim().equalsIgnoreCase("Fr") || str.trim().equalsIgnoreCase("Fri") || str.trim().equalsIgnoreCase("Frid")) n = 5; if(str.trim().equalsIgnoreCase("Sa") || str.trim().equalsIgnoreCase("Sat") || str.trim().equalsIgnoreCase("Satu")) n = 2; if(str.trim().equalsIgnoreCase("Su") || str.trim().equalsIgnoreCase("Sun") || str.trim().equalsIgnoreCase("Sund")) n = 0; switch(n){ case 1: System.out.println("星期一"); break; case 2: System.out.println("星期二"); break; case 3: System.out.println("星期三"); break; case 4: System.out.println("星期四"); break; case 5: System.out.println("星期五"); break; case 6: System.out.println("星期六"); break; case 0: System.out.println("星期日"); break; default: System.out.println("输入有误!"); break; } } } 【程序27】 题目:求100之内的素数 public class Prog27{ public static void main(String[] args){ int n = 100; System.out.print(n+"以内的素数:"); for(int i=2;i boolean flag = true; for(int i=2;i public static void main(String[] args){ int[] a = new int[]{31,42,21,50,12,60,81,74,101,93}; for(int i=0;i public static void main(String[] args){ int[][] a = new int[][] {{100,2,3,},{4,5,6},{17,8,9}}; matrSum(a); } private static void matrSum(int[][] a){ int sum1 = 0; int sum2 = 0; for(int i=0;i public static void main(String[] args){ int[] A = new int[]{0,8,7,5,9,1,2,4,3,12}; int[] B = sort(A); print(B); System.out.println(); System.out.print("请输入10个数的数组:"); Scanner scan = new Scanner(System.in); int a = scan.nextInt(); scan.close(); int[] C = insert(a,B); print(C); } //选择排序 private static int[] sort(int[] A){ int[] B = new int[A.length]; for(int i=0;i if(min>A[j]){ int temp = min; min = A[j]; A[j] = temp; } B[i] = min; } } B[A.length-1] = A[A.length-1]; return B; } //打印 private static void print(int[] A){ for(int i=0;i B[i+1] = a; for(int j=0;j int[] A = new int[]{1,2,3,4,5,6,7,8,9,}; print(A); System.out.println(); int[] B = reverse(A); print(B); } private static int[] reverse(int[] A){ for(int i=0;i for(int i=0;i //输入一个长整数 Scanner scan = new Scanner(System.in); long l = scan.nextLong(); scan.close(); //以下截取字符 String str = Long.toString(l); char[] ch = str.toCharArray(); int n = ch.length; if(n int[][] n = new int[10][21]; n[0][10] = 1; for(int i=1;i if(n[i][j]==0) System.out.print(" "); else{ if(n[i][j] System.out.print("请输入3个数:"); Scanner scan = new Scanner(System.in).useDelimiter("\\s"); int a = scan.nextInt(); int b = scan.nextInt(); int c = scan.nextInt(); scan.close(); if(a int t = a; a = c; c = t; } if(b public static void main(String[] args){ System.out.print("请输入一组数:"); Scanner scan = new Scanner(System.in).useDelimiter("\\s"); int[] a = new int[50]; int m = 0; while(scan.hasNextInt()){ a[m++] = scan.nextInt(); } scan.close(); int[] b = new int[m]; for(int i=0;i public static void main(String[] args){ final int N = 10; System.out.print("请输入10个数的数组:"); Scanner scan = new Scanner(System.in); int[] a = new int[N]; for(int i=0;i if(isIn[index]){ countNum++; if(countNum==3){ countNum = 0; isIn[index] = false; inCount--; } } index++; if(index==n) index = 0; } for(int i=0;i System.out.print("请输入一串字符:"); Scanner scan = new Scanner(System.in).useDelimiter("\\n"); String strIn = scan.next(); scan.close(); char[] ch = strIn.toCharArray(); System.out.println(strIn+"共"+(ch.length-1)+"个字符"); } } 【程序39】 题目:编写一个函数,输入n为偶数时,调用函数求1/2+1/4+...+1/n,当输入n为奇数时,调用函数1/1+1/3+...+1/n(利用指针函数) import java.util.Scanner; public class Prog39{ public static void main(String[] args){ System.out.print("请输入一个整数:"); Scanner scan = new Scanner(System.in); int n = scan.nextInt(); scan.close(); if(n%2==0) System.out.println("结果:"+even(n)); else System.out.println("结果:"+odd(n)); } //奇数 static double odd(int n){ double sum = 0; for(int i=1;i double sum = 0; for(int i=2;i public static void main(String[] args){ String[] str = {"abc","cad","m","fa","f"}; for(int i=str.length-1;i>=1;i--){ for(int j=0;j String temp = str[j]; str[j] = str[j+1]; str[j+1] = temp; } } } for(String subStr:str) System.out.print(subStr+" "); } } 【程序41】 题目:海滩上有一堆桃子,五只猴子来分。第一只猴子把这堆桃子凭据分为五份,多了一个,这只猴子把多的一个扔入海中,拿走了一份。第二只猴子把剩下的桃子又平均分成五份,又多了一个,它同样把多的一个扔入海中,拿走了一份,第三、第四、第五只猴子都是这样做的,问海滩上原来最少有多少个桃子? public class Prog41{ public static void main(String[] args){ int n; n = fun(0); System.out.println("原来有"+n+"个桃子"); } private static int fun(int i){ if(i==5) return 1; else return fun(i+1)*5+1; } } 【程序42】 题目:809*??=800*??+9*??+1 其中??代表的两位数,8*??的结果为两位数,9*??的结果为3位数。求??代表的两位数,及809*??后的结果。 public class Prog42{ public static void main(String[] args){ int n = 0; boolean flag = false; for(int i=10;i public static void main(String[] args){ int count = 0; //声明由数字组成的数 int n = 8; //一位数 count = n/2; //两位数 count += (n-1)*n/2; //三位数 count += (n-1)*n*n/2; //四位数 count += (n-1)*n*n*n/2; //五位数 count += (n-1)*n*n*n*n/2; //六位数 count += (n-1)*n*n*n*n*n/2; //七位数 count += (n-1)*n*n*n*n*n*n/2; System.out.println("0-7所能组成的奇数个数:"+count); } } 【程序44】 题目:一个偶数总能表示为两个素数之和。 import java.util.Scanner; public class Prog44{ public static void main(String[] args){ System.out.print("请输入一个偶数:"); Scanner scan = new Scanner(System.in); int n = scan.nextInt(); scan.close(); if(n%2!=0){ System.out.println("您输入的不是偶数!"); return; } twoAdd(n); } //偶数分解为素数之和 private static void twoAdd(int n){ for(int i=2;i System.out.println(n+"="+(i)+"+"+(n-i)); break; } } } //判断素数 private static boolean isPrime(int m){ boolean flag = true; for(int i=2;i flag = false; break; } } return flag; } } 【程序45】 题目:判断一个素数能被几个9整除 import java.util.Scanner; public class Prog45{ public static void main(String[] args){ System.out.print("请输入一个数:"); Scanner scan = new Scanner(System.in); long l = scan.nextLong(); long n = l; scan.close(); int count = 0; while(n>8){ n /= 9; count++; } System.out.println(l+"能被"+count+"个9整除。"); } } 【程序46】 题目:两个字符串连接程序 public class Prog46{ public static void main(String[] args){ String str1 = "lao lee"; String str2 = "牛刀"; String str = str1+str2; System.out.println(str); } } 【程序47】 题目:读取7个数(1—50)的整数值,每读取一个值,程序打印出该值个数的*。 import java.util.Scanner; public class Prog47{ public static void main(String[] args){ System.out.print("请输入7个整数(1-50):"); Scanner scan = new Scanner(System.in); int n1 = scan.nextInt(); int n2 = scan.nextInt(); int n3 = scan.nextInt(); int n4 = scan.nextInt(); int n5 = scan.nextInt(); int n6 = scan.nextInt(); int n7 = scan.nextInt(); scan.close(); printStar(n1); printStar(n2); printStar(n3); printStar(n4); printStar(n5); printStar(n6); printStar(n7); } static void printStar(int m){ System.out.println(m); for(int i=0;i int n = 1234; int[] a = new int[4]; for(int i=3;i>=0;i--){ a[i] = n%10; n /= 10; } for(int i=0;i public static void main(String[] args){ String str = "I come from County DingYuan Province AnHui."; char[] ch = str.toCharArray(); int count = 0; for(int i=0;i //定义学生模型 String[] number = new String[5]; String[] name = new String[5]; float[][] grade = new float[5][3]; float[] sum = new float[5]; public static void main(String[] args) throws Exception{ Prog50 stud = new Prog50(); stud.input(); stud.output(); } //输入学号、姓名、成绩 void input() throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); //录入状态标识 boolean isRecord = true; while(isRecord){ try{ for(int i=0;i System.out.print("请输入第"+(j+1)+"门课成绩:"); grade[i][j] = Integer.parseInt(br.readLine()); } System.out.println(); sum[i] = grade[i][0]+grade[i][1]+grade[i][2]; } isRecord = false; }catch(NumberFormatException e){ System.out.println("请输入一个数字!"); } } } //输出文件 void output() throws IOException{ FileWriter fw = new FileWriter("E://java50//stud.txt"); BufferedWriter bw = new BufferedWriter(fw); bw.write("No. "+"Name "+"grade1 "+"grade2 "+"grade3 "+"average"); bw.newLine(); for(int i=0;i |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |