菜鸡学习day08
package day08;
import javax. print. DocFlavor;
import java. util. Arrays;
import java. util. Scanner;
public class D0801 {
public static void main ( String[ ] args) {
String str1 = new String ( ) ;
System. out. println ( str1) ;
char [ ] array1 = { 'a' , 'b' , 'c' } ;
String str2 = new String ( array1) ;
System. out. println ( str2) ;
byte [ ] array2 = { 65 , 66 , 67 } ;
String str3 = new String ( array2) ;
System. out. println ( str3) ;
String str4 = "abc" ;
String str5 = "abc" ;
String str6 = "ABC" ;
System. out. println ( str4. equals ( str5) ) ;
System. out. println ( str4. equals ( str2) ) ;
System. out. println ( str5. equalsIgnoreCase ( str6) ) ;
int length = str4. length ( ) ;
System. out. println ( "str4长度是:" + length) ;
String str7 = str4. concat ( str5) ;
System. out. println ( "拼接后为:" + str7) ;
char str8 = str7. charAt ( 2 ) ;
System. out. println ( "str7的2位置处的字符为:" + str8) ;
int num = str7. indexOf ( "bc" ) ;
System. out. println ( "bc首次出现的位置是:" + num) ;
String str9 = str7. substring ( 2 ) ;
System. out. println ( "截取后为:" + str9) ;
String str10 = str7. substring ( 2 , 5 ) ;
System. out. println ( "截取后为:" + str10) ;
char [ ] str11 = str7. toCharArray ( ) ;
System. out. println ( str11) ;
byte [ ] str12 = str7. getBytes ( ) ;
System. out. println ( str12) ;
String str13 = str7. replace ( "bc" , "qw" ) ;
System. out. println ( str13) ;
String[ ] array3 = str7. split ( "a" ) ;
for ( int i = 0 ; i < array3. length; i++ ) {
System. out. println ( array3[ i] ) ;
}
int [ ] array4 = { 1 , 2 , 3 } ;
String str14 = method1 ( array4) ;
System. out. println ( str14) ;
Scanner sc = new Scanner ( System. in) ;
System. out. println ( "输入一个字符串:" ) ;
String str15 = sc. next ( ) ;
method2 ( str15) ;
Student stu1 = new Student ( ) ;
stu1. setName ( "小明" ) ;
stu1. setAge ( 17 ) ;
Student. setRoom ( "503" ) ;
System. out. println ( "姓名:" + stu1. getName ( ) + " 年龄:"
+ stu1. getAge ( ) + " 教室:" + Student. getRoom ( ) ) ;
Student stu2 = new Student ( ) ;
stu2. setName ( "小红" ) ;
stu2. setAge ( 16 ) ;
System. out. println ( "姓名:" + stu2. getName ( ) + " 年龄:"
+ stu2. getAge ( ) + " 教室:" + Student. getRoom ( ) ) ;
int [ ] array5 = { 9 , 8 , 7 , 6 , 5 , 4 , 3 , 2 , 1 } ;
String str16 = Arrays. toString ( array5) ;
System. out. println ( str16) ;
Arrays. sort ( array5) ;
System. out. println ( Arrays. toString ( array5) ) ;
String str17 = "423dsa23周cRsDSA$@^&" ;
char [ ] ch1 = str17. toCharArray ( ) ;
System. out. println ( Arrays. toString ( ch1) ) ;
Arrays. sort ( ch1) ;
System. out. println ( Arrays. toString ( ch1) ) ;
for ( int i = 0 ; i < ch1. length; i++ ) {
System. out. print ( ch1[ ch1. length- i- 1 ] ) ;
}
double num1 = - 3.14 ;
System. out. println ( Math. abs ( num1) ) ;
System. out. println ( Math. ceil ( num1) ) ;
System. out. println ( Math. floor ( num1) ) ;
System. out. println ( Math. round ( num1) ) ;
double min = - 10.8 ;
double max = 5.9 ;
int b = 0 ;
for ( double i = min; i < max; i++ ) {
double a = Math. abs ( i) ;
System. out. println ( a) ;
if ( a > 6 || a < 2.1 ) {
b++ ;
}
}
System. out. println ( "符合条件的个数为:" + b) ;
}
public static String method1 ( int [ ] array) {
String str = "[" ;
for ( int i = 0 ; i < array. length- 1 ; i++ ) {
str += "word" + array[ i] + "#" ;
}
str += "word" + array[ array. length- 1 ] + "]" ;
return str;
}
public static void method2 ( String str) {
char [ ] ch = str. toCharArray ( ) ;
int a = 0 , b = 0 , c = 0 , d = 0 ;
for ( int i = 0 ; i < ch. length; i++ ) {
if ( ch[ i] >= '0' && ch[ i] <= '9' ) {
a++ ;
}
else if ( ch[ i] >= 'A' && ch[ i] <= 'Z' ) {
b++ ;
}
else if ( ch[ i] >= 'a' && ch[ i] <= 'z' ) {
c++ ;
}
else {
d++ ;
}
}
System. out. println ( "数字个数为:" + a) ;
System. out. println ( "大写字母个数为:" + b) ;
System. out. println ( "小写字母个数为:" + c) ;
System. out. println ( "其他个数为:" + d) ;
}
}
package day08;
public class Student {
String name;
int age;
static String room;
static {
System. out. println ( "先执行了静态代码块。" ) ;
}
public Student ( ) {
}
public Student ( String name, int age) {
this . name = name;
this . age = age;
}
public static String getRoom ( ) {
return room;
}
public static void setRoom ( String room) {
Student. room = room;
}
public String getName ( ) {
return name;
}
public void setName ( String name) {
this . name = name;
}
public int getAge ( ) {
return age;
}
public void setAge ( int age) {
this . age = age;
}
}