Within 1.100 and 7 related numbers
// 100 within 7 related to the number; Public Static void main1 (string[] args) { for (int i=1;i<=100;i++) { if (i%7==0 | | i%10==7 | | i/10==7) { System.out.println (i);}} }
Within 2.100 of all numbers and
// 100 or less of all numbers; Public Static void main2 (String arg[]) { int sum=0; for (int i=1;i<=100;i++) { sum=sum+i; } SYSTEM.OUT.PRINTLN (sum); }
3.123 () 45 () 67 () 8 () 9=100; brackets can only fill in + or-
//123 () 45 () 67 () 8 () 9=100; brackets can only fill in + or-; Public Static voidmain3 (String arg[]) { for(intI=-1;i<=1;i=i+2){ for(intA=-1;a<=1;a=a+2){ for(intB=-1;b<=1;b=b+2){ for(intC=-1;c<=1;c=c+2){ if(123+45*i+67*a+8*b+9*c==100) {System.out.println (i+ "" +a+ "" +b+ "" +c); } } } } } }
4. How many times will a 0.0001-metre piece of paper be folded over the height of the Himalaya delete?
// How many times will a 0.0001-metre paper fold more than the Himalaya-deleted height? ; public static void Main4 (String arg[]) { double h=0.0001; int cs=0; for (int i=1;i>0;i++ ++ =h*2; if (H>8848 break ; } } }
5. Multiplication Formula table
// 5 multiplication Tables for (int i=1;i<10;i++) { for (int j=1;j<=i;j++) { System.out.print (J+ "*" +i+ "=" +j*i+ "\ T"); } System.out.println (); }
6. Enter the number of rows in the triangle and print the triangle
//Enter the number of rows in the triangle and print the triangle; Public Static voidmain5 (String ags[]) {Scanner SC=NewScanner (system.in); System.out.println ("Please enter the number of rows in the upper triangle:"); intA=Sc.nextint (); for(inti=1;i<=a;i++){ for(intj=a-i;j>=1;j--) {System.out.print (" "); } for(intj=1;j<=2*i-1;j++) {System.out.print ("*"); } System.out.println (""); } }
7. Enter the number of rows above the triangle to print the diamond
//Enter the number of rows above the triangle and print the diamond; Public Static voidmain6 (String ags[]) {Scanner SC=NewScanner (system.in); System.out.print ("Please enter the number of rows in the upper triangle:"); intA=Sc.nextint (); for(inti=1;i<=a;i++){ for(intj=a-i;j>=1;j--) {System.out.print (" "); } for(intj=1;j<=2*i-1;j++) {System.out.print ("*"); } System.out.println (""); } for(inti=1;i<=a-1;i++){ for(intj=1;j<=i;j++) {System.out.print (" "); } for(intj=2* (a-i) -1;j>=1;j--) {System.out.print ("*"); } System.out.println (""); } }
8. Enter 5 scores, output the highest and lowest score and average
//input 5 scores, output the highest score and the lowest score and average; Public Static voidmain7 (String ags[]) {intMax=0, min=1000, sum=0; Doubleavg; int[] fen=New int[5]; Scanner SC=NewScanner (system.in); for(inti=0;i<fen.length;i++) {System.out.print ("Please enter" + (I+1) + "score:"); Fen[i]=Sc.nextint (); } for(inti=0;i<fen.length;i++){ if(max<Fen[i]) {Max=Fen[i]; } if(min>Fen[i]) {min=Fen[i]; } Sum=sum+Fen[i]; } avg=1.0*sum/fen.length-2; System.out.println (The average score after "+max+" and the Minimum "+min+" is "+avg+" Thanks! "); }
9. Enter 7 numbers and output these 7 numbers in order of size
//Enter 7 numbers, and output these 7 numbers in order of size; Public Static voidMain (String ags[]) {Scanner SC=NewScanner (system.in); int[] px=New int[7]; for(inti=0;i<px.length;i++) {System.out.print ("Please enter" + (i+1) + "number:"); Px[i]=Sc.nextint (); } for(inti=1;i<=px.length-1;i++){ for(intj=1;j<=px.length-i;j++){ if(px[j]<px[j-1]){ intZ=px[j-1]; Px[j-1]=Px[j]; PX[J]=Z; } } } for(intj=0;j<px.length;j++) {System.out.print (Px[j]+ "\ T"); } }
Exhaustive, iterative and bubbling examples in the java,for cycle