当前位置: 首页 > news >正文

二级Java程序题--01基础操作:源码大全(all)

目录

1.基本操作(源代码):

1.1

1.2

1.3

1.4

1.5

1.6

1.7

1.8

1.9

1.10

1.11

1.12

1.13

1.14

1.15

1.16

1.17

1.18

1.19

1.20

1.21

1.22

1.23

1.24

1.25

1.26

1.27

1.28

1.29

1.30

1.31

1.32

1.33

1.34

1.35

1.36

1.37

1.38

1.39

1.40

1.41

1.42

1.43

1.44

1.45

1.46

1.47

1.48

1.49(star)

1.50

1.51

1.52(star)

1.53

1.54


1.基本操作(源代码):

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';elsegrade = '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 += arri; 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.PIrrr*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;elsem=(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 = bf; 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);
}

}

相关文章:

二级Java程序题--01基础操作:源码大全(all)

目录 1.基本操作&#xff08;源代码&#xff09;&#xff1a; 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 1.10 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.18 1.19 1.20 1.21 1.22 1.23 1.24 1.25 1.26 1.27 1.28 1.29 1.30 1.31 1.32 1.33 1.34 1.…...

伪分布HBase的安装与部署

1.实训目标 &#xff08;1&#xff09;熟悉掌握使用在Linux下安装伪分布式HBase。 &#xff08;2&#xff09;熟悉掌握使用在HBase伪分布式下使用自带Zookeeper。 2.实训环境 环境 版本 说明 Windows 10系统 64位 操作电脑配置 VMware 15 用于搭建所需虚拟机Linux系统 …...

Python语言基础与应用-北京大学-陈斌-P40-39-基本扩展模块/上机练习:计时和文件处理-给算法计时-上机代码

Python语言基础与应用-北京大学-陈斌-P40-39-基本扩展模块/上机练习&#xff1a;计时和文件处理-给算法计时-上机代码 上机代码&#xff1a; # 基本扩展模块训练 给算法计时 def factorial(number): # 自定义一个计算阶乘的函数i 1result 1 # 变量 result 用来存储每个数的阶…...

Sqllab第一关通关笔记

知识点&#xff1a; 明白数值注入和字符注入的区别 数值注入&#xff1a;通过数字运算判断&#xff0c;1/0 1/1 字符注入&#xff1a;通过引号进行判断&#xff0c;奇数个和偶数个单引号进行识别 联合查询&#xff1a;union 或者 union all 需要满足字段数一致&…...

【Golang星辰图】图像和多媒体处理的创新之路:Go语言的无限潜能

图像处理、音视频编辑&#xff0c;Go语言不再局限&#xff1a;揭秘opencv和goav的威力 前言: 在当今的数字时代&#xff0c;图像处理和多媒体技术在各个领域中的应用越来越广泛。无论是计算机视觉、图像处理还是音视频处理&#xff0c;选择合适的库和工具至关重要。本文将介绍…...

MES管理系统中电子看板都有哪些类型?

随着工业信息化和智能制造的不断发展&#xff0c;MES管理系统已经成为现代制造业不可或缺的重要工具。MES管理系统通过集成和优化生产过程中的各个环节&#xff0c;实现对生产过程的实时监控、调度和管理&#xff0c;提高生产效率和质量。 在生产制造过程中&#xff0c;看板管…...

【Flutter 面试题】await for 如何使用?

【Flutter 面试题】await for 如何使用&#xff1f; 文章目录 写在前面解答补充说明完整代码示例运行结果详细说明 写在前面 &#x1f64b; 关于我 &#xff0c;小雨青年 &#x1f449; CSDN博客专家&#xff0c;GitChat专栏作者&#xff0c;阿里云社区专家博主&#xff0c;51…...

MongoDB聚合运算符:$dayOfWeek

$dayOfWeek返回日期中“星期”的部分&#xff0c;值的范围1-7&#xff0c;即Sunday~Saturday。 语法 { $dayOfWeek: <dateExpression> }参数说明&#xff1a; <dateExpression>为可被解析为Date、Timestamp或ObjectID的表达式<dateExpression>也可以是一个…...

Visual Studio单步调试中监视窗口变灰的问题

在vs调试中&#xff0c;写了这样一条语句 while((nfread(buf, sizeof(float), N, pf))>0) 然而&#xff0c;在调试中&#xff0c;只要一执行while这条语句&#xff0c;监视窗口中的变量全部变为灰色&#xff0c;不能查看&#xff0c;是程序本身并没有报错&#xff0c;能够继…...

【Selenium】selenium介绍及工作原理

一、Selenium介绍 用于Web应用程序测试的工具&#xff0c;Selenium是开源并且免费的&#xff0c;覆盖IE、Chrome、FireFox、Safari等主流浏览器&#xff0c;通过在不同浏览器中运行自动化测试。支持Java、Python、Net、Perl等编程语言进行自动化测试脚本编写。 官网地址&…...

【2024-完整版】python爬虫 批量查询自己所有CSDN文章的质量分:附整个实现流程

【2024】批量查询CSDN文章质量分 写在最前面一、分析获取步骤二、获取文章列表1. 前期准备2. 获取文章的接口3. 接口测试&#xff08;更新重点&#xff09; 三、查询质量分1. 前期准备2. 获取文章的接口3. 接口测试 四、python代码实现1. 分步实现2. 批量获取文章信息3. 从exce…...

Nuxt3: useFetch使用过程常见一种报错

一、问题描述 先看一段代码&#xff1a; <script setup> const fetchData async () > {const { data, error } await useFetch(https://api.publicapis.org/entries);const { data: data2, error: error2 } await useFetch(https://api.publicapis.org/entries);…...

当代计算机语言占比分析

在当今快速发展的科技领域&#xff0c;计算机语言作为程序员的工具之一&#xff0c;扮演着至关重要的角色。随着技术的不断演进&#xff0c;各种编程语言层出不穷&#xff0c;但在实际开发中&#xff0c;哪些计算机语言占据主导地位&#xff1f;本文将对当代计算机语言的占比进…...

基于大模型和向量数据库的 RAG 示例

1 RAG 介绍 RAG是一种先进的自然语言处理方法&#xff0c;它结合了信息检索和文本生成技术&#xff0c;用于提高问答系统、聊天机器人等应用的性能。 2 RAG 的工作流程 文档加载&#xff08;Document Loading&#xff09; 从各种来源加载大量文档数据。这些文档…...

【C语言】比较两个字符串大小,strcmp函数

目录 一&#xff0c;strcmp函数 1&#xff0c;strcmp函数 2&#xff0c;函数头文件&#xff1a; 3&#xff0c;函数原型&#xff1a; 4&#xff0c;返回取值&#xff1a; 二&#xff0c;代码实现 三&#xff0c;小结 一&#xff0c;strcmp函数 1&#xff0c;strcmp函数 …...

深入理解与应用Keepalive机制

目录 引言 一、VRRP协议 &#xff08;一&#xff09;VRRP概述 1.诞生背景 2.基本理论 &#xff08;二&#xff09;VRRP工作原理 &#xff08;三&#xff09;VRRP相关术语 二、keepalive基本理论 &#xff08;一&#xff09;基本性能 &#xff08;二&#xff09;实现原…...

嵌入(embedding)概念

嵌入&#xff08;embedding&#xff09;在数学和相关领域中的确是指将一个数学对象在保持其某些关键性质不变的前提下&#xff0c;注入到一个更大或更高维的空间中。这个过程不仅仅是简单的映射&#xff0c;而是要求注入的对象在新空间中的表现形式能够完整反映原有对象的内在结…...

豆瓣书影音存入Notion

使用Python将图书和影视数据存放入Notion中。 &#x1f5bc;️介绍 环境 Python 3.10 &#xff08;建议 3.11 及以上&#xff09;Pycharm / Vs Code / Vs Code Studio 项目结构 │ .env │ main.py - 主函数、执行程序 │ new_book.txt - 上一次更新书籍 │ new_video.…...

Lucene 分词 示例代码

import org.apache.lucene.analysis.tokenattributes.CharTermAttribute; import org.apache.lucene.analysis.TokenStream; import org...

2.18 校招 实习 内推 面经

绿*泡*泡VX&#xff1a; neituijunsir 交流*裙 &#xff0c;内推/实习/校招汇总表格 1、自动驾驶一周资讯 - 李想回应“年终奖有点大”&#xff1b;智界升级为奇瑞独立事业部&#xff1b;小鹏汽车春节累计智驾总里程公布 自动驾驶一周资讯 - 李想回应“年终奖有点大”&…...

spring中事务失效的场景有哪些?

异常捕获处理 在方法中已经将异常捕获处理掉并没有抛出。 事务只有捕捉到了抛出的异常才可以进行处理&#xff0c;如果有异常业务中直接捕获处理掉没有抛出&#xff0c;事务是无法感知到的。 解决&#xff1a;在catch块throw抛出异常。 抛出检查异常 spring默认只会回滚非检…...

Visual Studio 2022之Release版本程序发送到其它计算机运行

目录 1、缺少dll​ 2、应用程序无法正常启动 3、This application failed to start because no Qt platform plugin could be initialized. 代码在Debug模式下正常运行&#xff0c;然后切换到Release模式下&#xff0c;也正常运行&#xff0c;把第三方平台的dll拷贝到exe所在…...

Xcode下载模拟器报错Could not download iOS 17.4 Simulator (21E213).

xcode14以后最小化安装包&#xff0c;从而将模拟器不集中在安装包中 因此xcode14至以后的版本安装后第一次启动会加载提示安装模拟器的提示框 或者根据需要到xcode中进行所需版本|平台的模拟器进行安装 Xcode > Settings > Platforms 问题来了尝试多次都安装失败例如…...

mac在终端设置代理

前言 本篇文章介绍如何在mac终端设置代理服务器&#xff0c;有时候&#xff0c;我们需要在终端进行外网的资源访问&#xff0c;比如我构建v8引擎项目的时候&#xff0c;需要使用gclient更新组件和下载构建工具。如果单单设置了计算机的代理&#xff0c;依然是无法下载资源的&a…...

傅立叶之美:深入研究傅里叶分析背后的原理和数学

一、说明 T傅里叶级数及其伴随的推导是数学在现实世界中最迷人的应用之一。我一直主张通过理解数学来理解我们周围的世界。从使用线性代数设计神经网络&#xff0c;从混沌理论理解太阳系&#xff0c;到弦理论理解宇宙的基本组成部分&#xff0c;数学无处不在。 当然&#xff0c…...

golang学习随便记16-反射

为什么需要反射 下面的例子中编写一个 Sprint 函数&#xff0c;只有1个参数&#xff08;类型不定&#xff09;&#xff0c;返回和 fmt.Fprintf 类似的格式化后的字符串。实现方法大致为&#xff1a;如果参数类型本身实现了 String() 方法&#xff0c;那调用 String() 方法即可…...

识别恶意IP地址的有效方法

在互联网的环境中&#xff0c;恶意IP地址可能会对网络安全造成严重威胁&#xff0c;例如发起网络攻击、传播恶意软件等。因此&#xff0c;识别恶意IP地址是保护网络安全的重要一环。IP数据云将探讨一些有效的方法来识别恶意IP地址。 IP地址查询&#xff1a;https://www.ipdata…...

探索信号处理:低通滤波器的原理与应用

在信号处理领域&#xff0c;滤波器的应用至关重要&#xff0c;它能够帮助我们从复杂的信号中提取需要的信息&#xff0c;而低通滤波器则是其中一种被广泛应用的滤波器类型。本文旨在深入探讨低通滤波器的基本原理、主要类型以及在实际应用中的作用和实现方式。 ### 1. 低通滤波…...

计算机网络:应用层知识点汇总

文章目录 一、网络应用模型二、域名系统&#xff08;DNS&#xff09;三、文本传输协议&#xff08;FTP&#xff09;四、电子邮件五、万维网和HTTP协议 一、网络应用模型 p2p也就是对等模型 二、域名系统&#xff08;DNS&#xff09; 我们知道&#xff0c;随着人们建立一个网站…...

金三银四!一个年薪160W+的就业方向!

前言 随着越来越多的科技大厂加入鸿蒙生态建设&#xff0c;鸿蒙开发人才正在市场上被争抢。资深工程师开出的年薪高达近百万&#xff0c;架构师更是高至160万&#xff0c;真可谓“鸿蒙猿年薪超百万”。如何抓住新技术红利&#xff0c;尽早上车&#xff1f;你会成为下一个鸿蒙开…...