} }
¡¾³ÌÐò26¡¿ ÌâÄ¿£ºÇëÊäÈëÐÇÆÚ¼¸µÄµÚÒ»¸ö×ÖĸÀ´ÅжÏÒ»ÏÂÊÇÐÇÆÚ¼¸£¬Èç¹ûµÚÒ»¸ö×ÖĸһÑù£¬Ôò¼ÌÐø Åжϵڶþ¸ö×Öĸ¡£ import java.util.*; public class lianxi26 {
public static void main(String[] args) { getChar tw = new getChar();
System.out.println(\ÇëÊäÈëÐÇÆÚµÄµÚÒ»¸ö´óд×Öĸ£º\ char ch = tw.getChar(); switch(ch) { case 'M':
System.out.println(\ break; case 'W':
System.out.println(\ break; case 'F':
System.out.println(\ break; case 'T': {
System.out.println(\ÇëÊäÈëÐÇÆÚµÄµÚ¶þ¸ö×Öĸ£º\ char ch2 = tw.getChar();
if(ch2 == 'U') {System.out.println(\
else if(ch2 == 'H') {System.out.println(\ else {System.out.println(\ÎÞ´Ëд·¨£¡\ } }; break; case 'S': {
System.out.println(\ÇëÊäÈëÐÇÆÚµÄµÚ¶þ¸ö×Öĸ£º\ char ch2 = tw.getChar();
if(ch2 == 'U') {System.out.println(\
else if(ch2 == 'A') {System.out.println(\ else {System.out.println(\ÎÞ´Ëд·¨£¡\ } };
break;
default:System.out.println(\ÎÞ´Ëд·¨£¡\} } }
class getChar{
public char getChar() {
Scanner s = new Scanner(System.in); String str = s.nextLine(); char ch = str.charAt(0); if(ch<'A' || ch>'Z') {
System.out.println(\ÊäÈë´íÎó£¬ÇëÖØÐÂÊäÈë\ ch=getChar(); }
return ch; } }
¡¾³ÌÐò27¡¿
ÌâÄ¿£ºÇó100Ö®ÄÚµÄËØÊý
//ʹÓóýsqrt(n)µÄ·½·¨Çó³öµÄËØÊý²»°üÀ¨2ºÍ3 public class lianxi27 {
public static void main(String[] args) { boolean b =false;
System.out.print(2 + \ System.out.print(3 + \ for(int i=3; i<100; i+=2) {
for(int j=2; j<=Math.sqrt(i); j++) { if(i % j == 0) {b = false; break; } else{b = true;} }
if(b == true) {System.out.print(i + \ } } }
//¸Ã³ÌÐòʹÓóý1Î»ËØÊýµÃ2λ·½·¨£¬ÔËÐÐЧÂʸßͨÓÃÐԲ public class lianxi27a {
public static void main(String[] args) { int[] a = new int[]{2, 3, 5, 7};
for(int j=0; j<4; j++)System.out.print(a[j] + \ boolean b =false;
for(int i=11; i<100; i+=2) { for(int j=0; j<4; j++) {
if(i % a[j] == 0) {b = false; break; } else{b = true;} }
if(b == true) {System.out.print(i + \ }
} }
¡¾³ÌÐò28¡¿
ÌâÄ¿£º¶Ô10¸öÊý½øÐÐÅÅÐò import java.util.*; public class lianxi28 {
public static void main(String[] args) { Scanner s = new Scanner(System.in); int[] a = new int[10];
System.out.println(\ÇëÊäÈë10¸öÕûÊý£º\ for(int i=0; i<10; i++) { a[i] = s.nextInt(); }
for(int i=0; i<10; i++) { for(int j=i+1; j<10; j++) { if(a[i] > a[j]) { int t = a[i]; a[i] = a[j]; a[j] = t; } } }
for(int i=0; i<10; i++) {
System.out.print(a[i] + \ } } }
¡¾³ÌÐò29¡¿
ÌâÄ¿£ºÇóÒ»¸ö3*3¾ØÕó¶Ô½ÇÏßÔªËØÖ®ºÍ import java.util.*; public class lianxi29 {
public static void main(String[] args) { Scanner s = new Scanner(System.in); int[][] a = new int[3][3];
System.out.println(\ÇëÊäÈë9¸öÕûÊý£º\ for(int i=0; i<3; i++) { for(int j=0; j<3; j++) { a[i][j] = s.nextInt(); } }
System.out.println(\ÊäÈëµÄ3 * 3 ¾ØÕóÊÇ:\ for(int i=0; i<3; i++) { for(int j=0; j<3; j++) {
System.out.print(a[i][j] + \
}
System.out.println(); }
int sum = 0;
for(int i=0; i<3; i++) { for(int j=0; j<3; j++) { if(i == j) { sum += a[i][j]; } } }
System.out.println(\¶Ô½ÇÏßÖ®ºÍÊÇ£º\} }
¡¾³ÌÐò30¡¿
ÌâÄ¿£ºÓÐÒ»¸öÒѾÅźÃÐòµÄÊý×é¡£ÏÖÊäÈëÒ»¸öÊý£¬ÒªÇó°´ÔÀ´µÄ¹æÂɽ«Ëü²åÈëÊý×éÖС£ //´Ë³ÌÐò²»ºÃ£¬Ã»ÓÐʹÓÃÕÛ°ë²éÕÒ²åÈë import java.util.*; public class lianxi30 {
public static void main(String[] args) {
int[] a = new int[]{1, 2, 6, 14, 25, 36, 37,55}; int[] b = new int[a.length+1];
int t1 =0, t2 = 0; int i =0;
Scanner s= new Scanner(System.in); System.out.print(\ÇëÊäÈëÒ»¸öÕûÊý£º\ int num = s.nextInt(); if(num >= a[a.length-1]) { b[b.length-1] = num;
for(i=0; i } else { for(i=0; i