class50
public class Class50 {
public static void main ( String [ ] args) {
int [ ] arr1= { 1 , 3 , 5 , 7 } ;
int [ ] arr2= { 2 , 4 , 6 , 8 } ;
int [ ] arr3= new int [ arr2. length+ arr1. length] ;
for ( int i= 0 ; i< arr1. length; i++ ) {
arr3[ i] = arr1[ i] ;
}
for ( int i= arr1. length; i< arr1. length+ arr2. length; i++ ) {
arr3[ i] = arr2[ i- 4 ] ;
}
bubblesort ( arr3) ;
for ( int i: arr3) {
System . out. print ( i+ ", " ) ;
}
}
public static void bubblesort ( int [ ] arr3) {
for ( int i= 0 ; i< arr3. length- 1 ; i++ ) {
for ( int j= 0 ; j< arr3. length- 1 - i; j++ ) {
if ( arr3[ j] > arr3[ j+ 1 ] ) {
swap ( arr3, j, j+ 1 ) ;
}
}
}
}
public static void swap ( int [ ] arr, int i, int j) {
arr[ i] = arr[ i] + arr[ j] ;
arr[ j] = arr[ i] - arr[ j] ;
arr[ i] = arr[ i] - arr[ j] ;
}
}
计算大小写字母,数字,其他符号
import java. util. Scanner ;
public class Count {
public static void main ( String [ ] args) {
System . out. print ( "请输入字符串:" ) ;
Scanner sc = new Scanner ( System . in) ;
String str = sc. nextLine ( ) ;
int count = 0 ;
int bigCount = 0 ;
int smallCount = 0 ;
int other = 0 ;
for ( int i = 0 , len = str. length ( ) ; i < len; i++ ) {
char c = str. charAt ( i) ;
if ( c >= 'A' && c <= 'Z' ) {
bigCount++ ;
} else if ( c >= 'a' && c <= 'z' ) {
smallCount++ ;
} else if ( c >= '0' && c <= '9' ) {
count++ ;
} else {
other++ ;
}
}
System . out. println ( "大写字母:" + bigCount) ;
System . out. println ( "小写字母:" + smallCount) ;
System . out. println ( "数字:" + count) ;
System . out. println ( "其他字符:" + other) ;
}
}
Cat类
public class Cat {
String name;
String gender;
int age;
String master;
String color;
public String getName ( ) {
return name;
}
public void setName ( String name) {
this . name = name;
}
public String getGender ( ) {
return gender;
}
public void setGender ( String gender) {
this . gender = gender;
}
public int getAge ( ) {
return age;
}
public void setAge ( int age) {
this . age = age;
}
public String getMaster ( ) {
return master;
}
public void setMaster ( String master) {
this . master = master;
}
public String getColor ( ) {
return color;
}
public void setColor ( String color) {
this . color = color;
}
}
登录案例:
1.用户类
public class Admin {
String username;
String password;
Object [ ] arr1= new Object [ 50 ] ;
Object [ ] arr2= new Object [ 50 ] ;
public String getUsername ( ) {
return username;
}
public void setUsername ( String username) {
this . username = username;
}
public String getPassword ( ) {
return password;
}
public void setPassword ( String password) {
this . password = password;
}
}
2.工具类
import java. util. Scanner ;
public class Tools {
Scanner sc = new Scanner ( System . in) ;
Admin a = new Admin ( ) ;
public void register ( ) {
System . out. print ( "请输入您要注册的用户名:" ) ;
a. username = sc. nextLine ( ) ;
System . out. print ( "请输入您要注册的密码:" ) ;
a. password = sc. nextLine ( ) ;
for ( int i = 0 ; i < a. arr1. length; i++ ) {
if ( a. arr1[ i] == null && a. arr2[ i] == null ) {
a. arr1[ i] = a. username;
a. arr2[ i] = a. password;
System . out. println ( "注册成功!" ) ;
break ;
}
}
}
public void login ( ) {
System . out. print ( "请输入您要登录的用户名:" ) ;
a. username= sc. nextLine ( ) ;
System . out. print ( "请输入您要登录的密码:" ) ;
a. password= sc. nextLine ( ) ;
for ( int i= 0 ; i< a. arr1. length; i++ ) {
if ( a. arr1[ i] . equals ( a. username) && a. arr2[ i] . equals ( a. password) ) {
System . out. println ( "登录成功!" ) ;
break ;
} else {
System . out. println ( "登录失败!" ) ;
break ;
}
}
}
public void logout ( ) {
System . out. print ( "请输入您要注销的用户名:" ) ;
a. username= sc. nextLine ( ) ;
System . out. print ( "请输入您要注销的密码:" ) ;
a. password= sc. nextLine ( ) ;
for ( int i= 0 ; i< a. arr1. length; i++ ) {
if ( a. arr1[ i] . equals ( a. username) && a. arr2[ i] . equals ( a. password) ) {
a. arr1[ i] = null ;
a. arr2[ i] = null ;
break ;
} else {
System . out. println ( "用户名或密码错误!" ) ;
break ;
}
}
System . out. println ( "注销成功!" ) ;
}
public void query ( ) {
for ( int i= 0 ; i< a. arr1. length; i++ ) {
System . out. print ( a. arr1[ i] + ", " ) ;
System . out. print ( a. arr2[ i] ) ;
System . out. print ( "; " ) ;
}
}
}
3.控制类
import java. util. Scanner ;
public class Ctrl {
Scanner sc = new Scanner ( System . in) ;
Tools t = new Tools ( ) ;
Menu m = new Menu ( ) ;
public void menu1 ( ) {
m. menu ( ) ;
System . out. print ( "请输入您的选择:" ) ;
int number = sc. nextInt ( ) ;
while ( number> 0 && number< 6 ) {
switch ( number) {
case 1 :
t. register ( ) ;
menu1 ( ) ;
break ;
case 2 :
t. login ( ) ;
menu1 ( ) ;
break ;
case 3 :
t. logout ( ) ;
menu1 ( ) ;
break ;
case 4 :
t. query ( ) ;
menu1 ( ) ;
break ;
case 5 :
System . exit ( 0 ) ;
}
}
}
}
4.菜单类
public class Menu {
public void menu ( ) {
System . out. println (
"1.用户注册" + "\t" +
"2.用户注册" + "\t" +
"3.注销用户" + "\t" +
"4.查询用户" + "\t" +
"5.退出系统"
) ;
}
}
5.主函数
public class Test {
public static void main ( String [ ] args) {
Ctrl c = new Ctrl ( ) ;
c. menu1 ( ) ;
}
}