Topic:
First Question: Double circulation:
public classText01 {//finish the song sort effect public Static voidmain (string[] Args) {string[] zimu={"island", "Ocean", "pertty", "Sun",}; String [] Newzimu=NewString[zimu.length+1]; System.out.println ("song before inserting:"); for(inti = 0; I < zimu.length; i++) {System.out.print (zimu[i]+ "\ t"); newzimu[i]=zimu[i]; } String num= "hehe"; intIndex=newzimu.length+1; for(inti = 0; I < newzimu.length; i++) { if(newzimu[i].comparetoignorecase (num) > 0) {index=i; break; } } for(inti = newzimu.length-1; i > index; i--) {newzimu[i]= Newzimu[i-1]; } newzimu[index]=num; System.out.println (""); System.out.println ("after the song is inserted:"); for(inti = 0; I < newzimu.length; i++) {System.out.print (newzimu[i]+ "\ t"); } } }
The second topic: course cycle:
Importjava.util.Scanner; public classText02 {//a translator that implements a course name and a course number: enter the course code in the table below,//Output Course name, user can loop output (y means continue, n means exit) public Static voidmain (string[] Args) {Scanner input=NewScanner (system.in); BooleanBOOL =true; do{System.out.println ("please Enter the course number:"); intnum =Input.nextint (); Switch(num) { case1: System.out.println ("using the Java language to understand program logic"); break; case2: System.out.println ("developing a commercial site using HTML language"); break; case3: System.out.println ("managing and querying data using SQL server"); break; case4: System.out.println ("use C # to also send a database application"); break; default: System.out.println ("no such"); break; } System.out.println ("do you want to continue?" (y Continue) "); String Car=Input.next (); if(car.equals ("n") ) {bool=false; System.out.println ("end the program!"); } } while(bool); }}
Question Three: summation and:
public class Text03 { // 1~100 cumulative sum, but requires skipping all digits of 3 public staticvoid main (string[] Args) { int sum = 0; for (int i = 1; i <=; i++) { if (!) ( i% = = 3)) { + = i; } } System.out.println (sum);} }
Question Fourth: Lucky Draw
Importjava.util.Random;Importjava.util.Scanner; public classText04 {//complete the lucky guess function, the system randomly gives a two-digit number, and then lets you guess what the number, if guessed,//tip "you are winning!! "if not, The system will give you a hint that" your number is too big or too small ",//thus narrowing the result range, the game needs to record the number of guesses, public Static voidmain (string[] Args) {intCount = 0; Random Rand=NewRandom (); intNUM1 = Rand.nextint (100); Scanner Inputscanner=NewScanner (system.in); System.out.println ("please Enter a number:"); while(true) { intdata =Inputscanner.nextint (); if(data >Num1) {System.out.println ("big, please continue to enter:"); Count++; } Else if(data <Num1) {System.out.println ("small, please continue to enter:"); Count++; } Else{count++; System.out.println ("congratulations, you guessed it!!" Guess "+ count +" times "); break; } } }}
Question Fifth: Parallelogram
public classText05 {//print parallelogram using a double cycle public Static voidmain (string[] Args) { for(inti = 1; I <= 7; i++) { for(intK = 1; K <= 7-i; k++) {System.out.print (" "); } for(intj = 1; J <= 7; J + +) {System.out.print ("*"); } System.out.println (); } }}
Come on! well, good! ======== Zi Xin
The key knowledge of Java Foundation