目录
1.1
import javax.swing.JOptionPane; //导入JOptionPane类 public class Java_1 { public static void main( String args[] ) { //*********Found******** JOptionPane.showMessageDialog( null, "欢迎\n你\n参加\nJava\n考试!" ); System.exit( 0 ); // 结束程序 } } /* JOptionPane类的常用静态方法如下: showInputDialog() showConfirmDialog() showMessageDialog() showOptionDialog() */
1.2
//*********Found******** import java.applet.*; import java.awt.Graphics; //*********Found******** public class Java_1 extends Applet { public void paint( Graphics g ) { //*********Found******** g.drawString( "欢迎你来参加Java 语言考试!", 25, 25 ); } }
1.3
import java.applet.*; import java.awt.Graphics; //*********Found******** public class Java_1 extends Applet{ public void paint( Graphics g ) { //*********Found******** g.drawString( "欢迎你来参加Java 语言考试!", 25, 25 ); } }
1.4
//*********Found********** public class Java_1{ public static void main(String args[]) { byte b = 10; // 二进制表示00001010 //*********Found********** **byte c = 0X000f;** b = (byte)(b ^ c); //*********Found********** System.out.println("b的结果是:" +b); } }
1.5
public class Java_1{ //*********Found********** public static void main(String args[]){ String string="现在学习如何访问一个字符串"; System.out.println("字符串 \""+string+"\""); //*********Found********** System.out.println("字符串长度:"+string.length()); //*********Found********** System.out.println("其中第7个字符是:"+string.charAt(6)); char sub[] = new char[20]; System.out.print("从字节数组的第7到12获取字符是:"); string.getChars(6,12,sub,0); System.out.println(sub); } }
1.6
public class Java_1{ //*********Found********** public static void main(String args[]){ String string="现在学习如何访问一个字符串"; System.out.println("字符串 \""+string+"\""); //*********Found********** System.out.println("字符串长度:"+string.length()); //*********Found********** System.out.println("其中第7个字符是:"+string.charAt(6)); char sub[] = new char[20]; System.out.print("从字节数组的第7到12获取字符是:"); string.getChars(6,12,sub,0); System.out.println(sub); } }
1.7
import java.io.*; public class Java_1{ public static void main(String[] args) { int[] anArray; //声明一个整数型数组 //*********Found********** anArray = new int[10]; //创建一个整数数组对象s //*********Found********** for (int i = 0; i < anArray.length;i++) { //对数组中每个元素赋值并显示 anArray[i] = i; //*********Found********** System.out.print(i+ " "); } System.out.println(); } }
1.8
//*********Found********** import java.io.*; public class Java_1{ //*********Found********** public static void main(String[] args) throws Exception{ InputStreamReader ir; BufferedReader in; ir=new InputStreamReader(System.in); in=new BufferedReader(ir); System.out.println("输入年份是:"); //*********Found********** String s=in.readLine(); //*********Found********** int year=Integer.parseInt(s); if(year%4==0&&year%100!=0||year%400==0){ System.out.println(""+year+"年是闰年."); } else{ System.out.println(""+year+"年不是闰年."); } } }
1.9
//*********Found********** import java.io.*; public class Java_1 { public static void main(String[ ] args) throws IOException { InputStreamReader ir; BufferedReader in; int sum, x; String data; //*********Found********** sum = 0; ir = new InputStreamReader(System.in); in = new BufferedReader(ir); System.out.println("请输入5个整数:"); //*********Found********** for (int i = 1; i<=5; i++) { data = in.readLine(); x = Integer.parseInt(data); //*********Found********** if (x%2==0) sum += x; } System.out.println("偶数之和为"+ sum ); } }
1.10
import java.io.*; public class Java_1 { public static void main(String[ ] args) throws IOException { InputStreamReader ir; BufferedReader in; int max, x; String data; max = 0; ir = new InputStreamReader(System.in); in = new BufferedReader(ir); System.out.println("请输入5个正整数:"); //*********Found********** for (int i = 1; i <=5; i++) { data = in.readLine(); //*********Found********** x = Integer.parseInt (data); if ( max < x ) //*********Found********** max = x; } System.out.println("输入的最大值是 "+ max); } }
1.11
public class Java_1{ public static void main(String[] args){ //*********Found********** int[] scores = {90,80,75,67,53}; int best = 0; char grade; // 找出这组成绩中的最高分 //*********Found********** for (int i=0;i<5; i++){ //*********Found********** if (scores[i]>best) best = scores[i]; } //求各分数的等级并显示 for (int i=0; i<scores.length; i++){ if (scores[i] >= best - 10) grade = 'A'; //*********Found********** else if(scores[i] >= best - 20) grade = 'B'; else if (scores[i] >= best - 30) grade = 'C'; else if (scores[i] >= best - 40) grade = 'D'; else grade = 'F'; System.out.println("Student " + i + " score is " + scores[i] + " and grade is " + grade); } } }
1.12
//*********Found********** public class Java_1{ public static void main(String[] args){ int []a = {1,2,3,4,5,6,7,8}; int []b = {0,1,2,3,4,5,6,7}; int []c = new int[8]; int s=0; //*********Found********** for(int i=0;i<a.length;i++) c[i]=a[i]+b[i]; for(int j=c.length-1;j>=0;j--) //*********Found********** s=s+c[j]; //*********Found********** System.out.println("s="+s); } }
1.13
class MethodOverloading { void receive(int i) { System.out.println("Receive one int data"); System.out.println("i=" + i); } //*********Found********** void receive(int x, int y) { System.out.println("Receive two int data"); System.out.println("x=" + x + " y =" + y); } //*********Found********** void receive(double d) { System.out.println("Receive one double data"); System.out.println("d=" + d); } //*********Found********** void receive(String s) { System.out.println("Receive a string"); System.out.println("s="+s); } } public class Java_1 { public static void main(String args[]) { MethodOverloading mo = new MethodOverloading(); mo.receive(1); mo.receive(2, 3); mo.receive(12.56); mo.receive("very interesting, is not it?"); } }
1.14
public class Java_1 { public static void main(String[] args) { //*********Found********** for (int i=1;i<=5;i++){ for(int k=1;k<=5-i;k++) //*********Found********** System.out.print(" "); //*********Found********** for(int j = 1;j<=2*i-1;j++) System.out.print("*"); //*********Found********** System.out.println(); } } }
`
1.15
public class Java_1 { public static void main(String[] args) { int a,x = 2008; //*********Found********** System.out.print( x +"->" ); while( x != 0 ){ //*********Found********** a = x%10; System.out.print(a); //*********Found********** x = x/10; } } }
1.16
public class Java_1 { public static void main(String args[]) { int a[][] = {{2, 3, 4}, {4, 6, 5}}; int b[][] = {{1, 5, 2, 8}, {5, 9, 10, -3}, {2, 7, -5, -18}}; int c[][] = new int[2][4]; for (int i = 0; i < 2; i++) { for (int j = 0; j < 4; j++) { //*********Found******** c[i][j] =0 ; //*********Found******** for (int k = 0; k < 3; k++) //*********Found******** c[i][j] += a[i][k]*b[k][j]; System.out.print(c[i][j] + " "); } System.out.println(); } } }
1.17
public class Java_1{ public static void main(String[] args){ //*********Found******** int[] ages = {35,43,28,39,62,57,48,29,54,46}; int sum = 0, avg = 0; int tt = 0,fot = 0,fit = 0,st = 0; for (int i=0; i<ages.length; i++){ if (ages[i] <=40 ) tt++; else if (ages[i] >40 && ages[i]<=50) fot++; else if (ages[i] >50 && ages[i]<=60) //*********Found******** fit++; else st++; } //*********Found******** for (int i = 0; i<ages.length; i++) //*********Found******** sum += ages[i]; avg = sum/ages.length; System.out.println("<=40: "+tt+" 41-50: " +fot+" 51-60: " + fit +" >=61: " + st); } }
1.18
public class Java_1 { //*********Found******** public static void main(String args[]) { int arr[][] = {{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}, {16, 17, 18, 19, 20}, {21, 22, 23, 24, 25}}; //*********Found******** int i, j, sum=0; for (i = 0; i < 5; i++) for (j = 0; j < 5; j++) //*********Found******** if (i+j==4) sum += arr[i][j]; System.out.println(sum); } }
`
1.19
public class Java_1 { public static void main(String[] args) { int []a = {5,9,2,8,7}; int max = 0; int k = 0,t ; for(int i=0;i<5;i++){ //*********Found******** if (a[i]%2==0 && max < a[i]){ max = a[i]; //*********Found******** k=i; } } t = a[0]; a[0] = a[k]; a[k] = t; //*********Found******** for(int i=0;i<a.length;i++) System.out.print(a[i] + " "); } }
1.20
public class Java_1 { public static void main(String[] args) { //*********Found******** `int []f= new int[10];` f[0]=f[1]=1; //*********Found******** `for (int i=2;i<10;i++)` f[i]=f[i-1]+f[i-2]; //*********Found******** `for (int i=0;i<f.length;i++)` //*********Found******** `System.out.print(f[i]+" ");` } }
1.21
import javax.swing.JOptionPane; public class Java_1 { public static void main( String args[] ){ //变量初始化 int passes = 0, //考生通过的数目 failures = 0, //考生不通过的数目 student = 1, //学生计数器 result; //一门考生结果 String input, //用户输入的值 output; //输出字符串 //处理10名学生,用计数器控制循环 while ( student <= 10 ) { input = JOptionPane.showInputDialog( "输入结果(1=通过,2=不通过)" ); //*********Found********** result = Integer.parseInt( input ); if ( result == 1 ) passes = passes + 1; else failures = failures + 1; student = student + 1; } //结果处理 output = "通过: " + passes + "\n不通过: " + failures; if( passes > 8 ) output = output + "\n提高学费"; //*********Found********** JOptionPane.showMessageDialog( null, output, "对考试结果的分析示例", JOptionPane.INFORMATION_MESSAGE ); //*********Found********** System.exit( 0 ); } }
1.22
public class Java_1 extends TT { //*********Found********** `public static void main(String args[])` { Java_1 t = new Java_1("小龙"); } public Java_1(String s) { super(s); System.out.println("您好吗?"); } public Java_1() { this("我是文朋"); } } class TT { public TT() { System.out.println("多高兴啊!"); } public TT(String s) { //*********Found********** `this();` System.out.println("我是"+s); } }
1.23
public class Java_1 { //*********Found********** public static void main (String args[]) { new SimpleThread("第1").start(); new SimpleThread("第2").start(); } } //*********Found********** class SimpleThread extends Thread { public SimpleThread(String str) { super(str); } public void run() { for (int i = 0; i < 5; i++) { //*********Found********** System.out.println(i + " " + getName()); try { sleep((int)(2 * 100)); } catch (InterruptedException e) { } } System.out.println("运行! " + getName()); } }
1.24
//*********Found********** import javax.swing.*; public class Java_1 { //*********Found********** public static void main(String[] args) { System.out.println(); System.out.println("这是一个指定球半径,求球体积的程序。"); String input=JOptionPane.showInputDialog("请输入球半径。"); //*********Found********** double r=Double.parseDouble(input); System.out.println("当球的半径是" + r + "时,该球的体积是 " + (Math.PI*r*r*r*4/3)); System.exit(0); } }
1.25
// 阅读下列代码: public class Java_1 { //*********Found********** public static void main(String []args) { String s1=new String("你正在考试"); String s2=new String("你正在考试"); System.out.println(s1==s2); //*********Found********** System.out.println(s1.equals(s2)); } }
1.26
public class Java_1 { //*********Found********** public static void main(String []args) { char ch='d'; //*********Found********** switch(ch) { case 'a': System.out.print("a");break; case 'b': System.out.print("b"); case 'c': System.out.print("c");break; //*********Found********** default : System.out.print("abc"); } } }
`
1.27
public class Java_1 { public static void main(String[] args) { long sum; //*********Found********** sum =0; for(int i=1;i<8;i+=2){ long b=1; //*********Found********** for(int j=1; j<=i; j++) //*********Found********** b = b * j; System.out.println( i + "!= " + b); sum+=b; } System.out.println("sum=" + sum); } }
1.28
public class Java_1 { public static void main(String args[]) { int x,n; //*********Found******** n =0; for( x = 100 ; x <= 200 ; x++) if ( x % 9 == 0 ) { //*********Found******** System.out.print(" " + x); n++; //*********Found******** if ( n%5 ==0) System.out.println( ); } } }
1.29
public class Java_1 { public static void main(String args[]) { int i,count; //*********Found******** count =0; for( i=100 ; i <= 200 ; i++) //*********Found******** if ( i%3==0 ) count++; //*********Found******** System.out.println("Count = " + count); } }
1.30
//Interest.java //计算复杂利息 import java.text.DecimalFormat; import javax.swing.JOptionPane; import javax.swing.JTextArea; public class Java_1{ public static void main( String args[] ){ double amount, principal = 1000.0, rate = .05; DecimalFormat precisionTwo = new DecimalFormat( "0.00" ); //*********Found********** JTextArea outputTextArea = new JTextArea( 11, 20 ); outputTextArea.append( "年\t存款总计\n" ); for ( int year = 1; year <= 10; year++ ) { amount = principal * Math.pow( 1.0 + rate, year ); outputTextArea.append( year + "\t" + //*********Found********** precisionTwo.format( amount ) + "\n" ); } //*********Found********** JOptionPane.showMessageDialog( null, outputTextArea, "复合利息", JOptionPane.INFORMATION_MESSAGE ); System.exit( 0 ); } }
1.31
import javax.swing.JOptionPane; public class Java_1{ //*********Found********** public static void main( String args[] ){ PackageData d = new PackageData(); String output; output = "实例化后:\n" + d.toString(); d.x = 77; //修改包访问的数据 //*********Found********** d.s = "祝您成功!"; //修改包访问的数据 output += "\n修改数据后的访问结果:\n" + d.toString(); //*********Found********** JOptionPane.showMessageDialog( null, output, "对包的访问示范", JOptionPane.INFORMATION_MESSAGE ); System.exit( 0 ); } } class PackageData { int x; //访问包的实例变量 String s; //访问包的实例变量 //构造方法 public PackageData(){ x = 0; s = "Hello"; } public String toString(){ return "x: " + x + " s: " + s; } }
1.32
import javax.swing.*; import java.text.DecimalFormat; public class Java_1{ //*********Found********** public static void main( String args[] ){ SimpleTime t = new SimpleTime( 12, 30, 19 ); //*********Found********** JOptionPane.showMessageDialog( null, t.buildString(), " \"this\" 引用示范", JOptionPane.INFORMATION_MESSAGE ); System.exit( 0 ); } } class SimpleTime { private int hour, minute, second; public SimpleTime( int hour, int minute, int second ){ this.hour = hour; this.minute = minute; this.second = second; } public String buildString(){ //*********Found********** return "this.toString(): " + toString() + "\ntoString(): " + toString() + "\nthis (with implicit toString() call): " + this; } public String toString(){ DecimalFormat twoDigits = new DecimalFormat( "00" ); return twoDigits.format( this.hour ) + ":" + twoDigits.format( this.minute ) + ":" + twoDigits.format( this.second ); } }
1.33
import java.io.*; public class Java_1 { public static void main(String[] args) { char[] charArray = {'a','b','c','d','e','f','g','h','i'}; char c ; try{ //*********Found********** DataOutputStream out = new DataOutputStream( new FileOutputStream("test.dat")); for(int i =0; i<charArray.length; i++){ out.writeChar(charArray[i]); } out.close(); DataInputStream in = new DataInputStream( //*********Found********** new FileInputStream("test.dat")); while(in.available() != 0){ c=in.readChar(); System.out.print(c+" "); } System.out.println(); //*********Found********** in.close(); }catch(IOException e){} } }
1.34
//用2至20的偶数去初始化数组 import javax.swing.*; public class Java_1{ public static void main( String args[] ){ final int ARRAY_SIZE = 10; int n[]; //引用整形数组 String output = ""; //*********Found********* n = new int[ ARRAY_SIZE ]; //分配数组 //给数组赋值 for ( int i = 0; i < n.length; i++ ) n[ i ] = 2 + 2 * i; output += "数组下标\t值\n"; for ( int i = 0; i < n.length; i++ ) output += i + "\t" + n[ i ] + "\n"; //*********Found********** JTextArea outputArea = new JTextArea( 11, 10 ); outputArea.setText( output ); //*********Found********** JOptionPane.showMessageDialog( null, outputArea, "用2至20的偶数去初始化数组", JOptionPane.INFORMATION_MESSAGE ); System.exit( 0 ); } }
1.35
public class Java_1{ void equalsMethod1(){ //*********Found********** String s1= "how are you"; //*********Found********** char[] s2={'h','o','w',' ','a','r','e',' ','y','o','u'}; //*********Found********** System.out.println(s1==s2.toString()); } public static void main(String args[]){ Java_1 OperAndExp=new Java_1(); OperAndExp.equalsMethod1(); } }
1.36
import java.io.*; public class Java_1 { public static void main(String args[]) { int a=15,b=25,c=5,m; if(a>b){ //*********Found********** if(b>c) m=b; else //*********Found********** m=(a>c)? c:a; }else{ if(a>c) //*********Found********** m =a; else m=(b>c)? c:b; } //*********Found********** System.out.println("median = " + m); } }
1.37
import javax.swing.*; public class Java_1{ public static void main( String args[] ){ //*********Found********** StringBuffer buf = new StringBuffer( "Hello, how are you?" ); String output = "buf = " + buf.toString() + "\nlength = " + buf.length() + "\ncapacity = " + buf.capacity(); buf.ensureCapacity( 75 ); output += "\n\nNew capacity = " + buf.capacity(); buf.setLength( 10 ); //*********Found********** output+= "\n\nNew length = " + buf.length() + "\nbuf = " + buf.toString(); JOptionPane.showMessageDialog( null, output, "字符串缓存长度和容量的实例", //*********Found********** JOptionPane.INFORMATION_MESSAGE ); //*********Found********** System.exit( 0 ); } }
`
1.38
public class Java_1 { //*********Found********** public static void main(String args[]) { byte b = 8; //*********Found********** long g = 567L; float f = 3.1415f; double d = 2.789; int ii = 207; //*********Found********** long gg = g+ii; float ff = b*f; double dd = ff/ii+d; //*********Found********** System.out.print("ii= "+ii+" "); System.out.println("gg= "+gg); System.out.println("ff= "+ff); System.out.println("dd= "+dd); } }
`
1.39
import javax.swing.JOptionPane; public class Java_1{ public static void main( String args[] ){ int x, result; String xVal; //*********Found********** xVal = JOptionPane.showInputDialog( "输入1个整数:" ); //*********Found********** x = Integer.parseInt( xVal ); //*********Found********** result = x*x; JOptionPane.showMessageDialog(null, "该数的平方是" + result ); System.exit( 0 ); } }
`
1.40
public class Java_1 { public static void main(String[] args) { int i, k, n; //*********Found******** n= 0; //*********Found******** for (i = 0; i<10; i++) { k = i * 10 + 6; //*********Found******** if ( k%3==0) { System.out.print(k + " "); n++; } } System.out.println("\n" + "The number is " + n + "."); } }
1.41
public class Java_1{ public static void main(String[] args){ //**************found***************** int[] arrayOfInts = { 33, 88, 5, 458, 18, 107, 200, 8, 622, 127 }; int searchfor = 18; int i = 0; //**************found***************** boolean foundIt = false; for ( ; i<arrayOfInts.length; i++){ //**************found***************** if (arrayOfInts[i] == searchfor ){ foundIt = true; //**************found***************** break; } } if (foundIt) { System.out.println("Found " + searchfor + " at index " + i); } else { System.out.println(searchfor + "not in the array"); } } }
1.42
import java.lang.*; import java.util.*; public class Java_1 { public static void main(String[] args){ int n; double e = 1.0; System.out.print("请输入n: "); //***************************Found********************* `Scanner scan = new Scanner (System.in);` String nstr = scan.next(); //***************************Found********************* `n = Integer.parseInt(nstr);` double t = 1.0; for(int i=1;i<=n;i++){ //***************************Found********************* `t = t/i;` e = e + t; } System.out.print("e 的近似值为: "+e); } }
1.43
public class Java_1 { public static void main(String[] args) { //**********found********** char[] arrayOfChars = { 'A', 'B', 'A','D', 'E','F','G' }; char searchfor = 'A'; int i=0, j=0; //**********found********** while ( i < arrayOfChars.length) { if (arrayOfChars[i] == searchfor) { System.out.println("Found " + searchfor + " at index " + i); j++; } //**********found********** i++; } //**********found********** if (j>0) { System.out.println("The total amount of " + searchfor + " is " + j ); } else { System.out.println(searchfor + " is not in the array"); } } }
1.44
import java.util.*; import java.io.*; public class Java_1 { //**********found********** `static long sum =0;` public static void main(String[] args) { //**********found********** `for (int counter=0 ; counter <= 10; counter++){` System.out.printf("%d! = %d\n", counter, factorial(counter)); sum=sum+factorial(counter); } System.out.println("sum="+sum); } //**********found********** `public static long factorial(long number ) {` if (number <= 1) return 1; else return number * factorial(number - 1); } }
1.45
import java.lang.*; import java.util.*; public class Java_1 { public static void main(String [] args){ System.out.print("请输入n: "); //**********Found********** `Scanner scan = new Scanner (System.in);` String nstr = scan.next(); //**********Found********** `int n = Integer.parseInt(nstr);` int b = 6; long sum=0,item=b; for(int i=1;i<=n;i++){ sum += item; //**********Found********** `item = item * 10 + b;` } System.out.print(n + "项的和为 " + sum); } }
1.46
import java.io.*; import java.util.*; public class Java_1 { static int number=4; //**********Found********** static int[] t1 = new int[number]; public static void main(String[] args) { Java_1 work=new Java_1(); //**********Found********** work.sort(); } void sort(){ System.out.println("请输入4个数:"); //**********Found********** Scanner in_t1 = new Scanner(System.in); for(int i=0;i<number;i++){ t1[i]=in_t1.nextInt(); } for (int i = 0; i < t1.length; i++) { int pos = i; for (int j = i + 1; j < t1.length; j++) { //**********Found********** if (t1[pos] > t1[j]) pos = j; } if (pos != i) { t1[i] = t1[i] + t1[pos]; t1[pos] = t1[i] - t1[pos]; t1[i] = t1[i] - t1[pos]; } } for (int i = 0; i <= t1.length - 1; i++) System.out.print(t1[i] + "\t"); } }
1.47
public class Java_1{ public static void main(String[] args){ //**********Found********** int[] grades = {62,53,84,77,65,85,91,94,61,78,86,88}; int sum=0, avg = 0; int stus=0; int a=0,b=0,c=0,d=0,e=0; //**********Found********** for (int i=0; i<grades.length; i++){ if (grades[i] <60 ) e++; else if (grades[i] >=60 && grades[i]<=69) d++; else if (grades[i] >=70 && grades[i]<=79) c++; else if (grades[i] >=80 && grades[i]<=89) b++; else a++; //**********Found********** sum+= grades[i]; } //**********Found********** stus =grades.length; //**********Found********** avg = sum/stus; System.out.println(">=90: "+a+"; 80-89: " +b+"; 70-79: " + c +"; 60-69: " + d+"; <60: "+e); System.out.println(stus+" students, and the average is : "+avg); } }
1.48
import java.util.*; public class Java_1 { public static void main(String [] args) { int n; //***************************Found********************* Scanner scan=new Scanner ( System.in); String nstr=scan.next(); scan.close(); //***************************Found********************* n= Integer.parseInt(nstr); int[][] mat=new int[n][n]; for( int i=0;i<n;i++) for( int j=0;j<n;j++) mat[i][j]=(int)(Math.random()*101); for( int i=0;i<n;i++) { for( int j=0;j<n;j++) System.out.print(mat[i][j]+" "); //***************************Found********************* System.out.println(); } int diagSum=0; for(int i=0;i<n;i++) //***************************Found********************* diagSum+=mat[i][i]; System.out.print("主对角线值的和为: "+diagSum); } }
1.49(star)
public class Java_1 { public static void main(String[] args) { int i, j, k, t; int[] m = {10, 21, 123, 5, 94}; for (i = 0; i < m.length - 1; i++) { //**********Found********** k = i; //**********Found********** for (j = i+1; j < m.length; j++) { //**********Found********** if ( m[k]%10 > m[j]%10 ) { k = j; } } if (k != i) { t = m[i]; //**********Found********** m[i]=m[k]; m[k] = t; } } //**********Found********** for (i = 0; i < m.length; i++) { System.out.print(" " + m[i]); } System.out.println(); } }
1.50
public class Java_1 { public static void main(String[] args) { int i, j, a, b; int[][] m = {{1, 2, 3}, {1, 2, 3, 4}, {1, 2, 4, 300, 5}, {3, 5, 6, 8, 10, 9}}; a = 0; //**********Found********** b = 0; //**********Found********** for (i = 0; i < 4; i++) { //**********Found********** for (j = 0; j <m[i].length; j++) { //**********Found********** if ( m[a][b] < m[i][j]) { a = i; b = j; } } } //**********Found********** System.out.println("max=" + m[a][b] + ",row=" + a + ",col=" + b); } }
1.51
public class Java_1 { public static void main(String[] args) { int[] scores = {82, 75, 42, 92, 85, 78, 93, 65}; int i; int sum = scores[0]; //**********Found********** int max = 0; //**********Found********** for (i = 1; i < scores.length; i++) { //**********Found********** sum += scores[i]; if (max < scores[i] ) { max = scores[i]; } } //**********Found********** System.out.println("平均值:" + (float)sum/ i); System.out.println("最大值:" + max); } }
1.52(star)
import java.util.*; public class Java_1{ public static void main(String[] args){ int[] a = new int[15]; int i, j, k; int[][] b = new int[5][]; for (i = 0; i < b.length; i++) //**********Found********** b[i] = new int[i+1]; //**********Found********** Scanner scan = new Scanner(System.in); for (i = 0; i < a.length; i++) //**********Found********** a[i] = scan.nextInt(); k = 0; for (i = 0; i < b.length; i++) { //**********Found********** for (j = 0; j <b[i].length; j++) { //**********Found********** b[i][j] = a[k++]; System.out.print(String.format("%5d",b[i][j])); } System.out.println(); } } }
1.53
public class Java_1 { public static void main(String args[]) { int a = 3, d = 4; //**********Found********** int s = a; //**********Found********** for (int i = 1; i <= 9;i++) { //**********Found********** a = a+d; //**********Found********** s += a; } System.out.println("前十项的和为 " + s); } }
1.54
import java.util.Scanner; public class Java_1 { public static void main(String[] args) { int []a = new int[10]; int s = 0,n = 0; //**********Found********** Scanner scan = new Scanner(System.in); //**********Found********** for(int i=0;i<a.length;i++){ //**********Found********** a[i] = scan.nextInt(); if(a[i]%2==0){ //**********Found********** s += a[i]; //**********Found********** n = n+1; } } if(n!=0) System.out.println("偶数的平均值是 " + s/n); } }