import java.util.*;
public class Dome{
public static void addSname(String[] students){
Scanner sc = new Scanner(System.in);
for(int i=0;i<students.length;i++){
System.out.println("存储第"+(i+1)+"个姓名:");
students[i] = sc.next();
}
}
public static void printName(String[] students){
for(int i=0;i<students.length;i++){
String name = students[i];
System.out.println("第"+ (i+1) +"个同学姓名" + name);
}
}
public static String randomName(String[] students){
Random r = new Random();
int i = r.nextInt(students.length);
String name = students[i];
return name;
}
public static void main(String[] args){
System.out.println("---------随机点名-----------");
String[] students = new String[3];
addSname(students);
printName(students);
String randomName = randomName(students);
System.out.println("被点到名的同学是:" + randomName);
}
}
public class test11{
class Bank{
private double money;
public void addMoney(double money){
this.money=this.money+ money;
System.out.println("余额"+this.money);
}
public void outMoney(double money){
if(money>this.money){
System.out.println("余额不足!");
}else{
this.money=this.money- money;
System.out.println("取出"+money+"元,余额"+this.money);
}
}
public void getMoney(){
System.out.println("余额"+this.money);
}
}
public static void main(String[] args){
System.out.println("欢迎来到招商银行");
Bank p=new Bank(100);
addMoney( money);
outMoney( money);
System.out.println("请带好随身物品,欢迎下次光临");
}
}
原文地址:https://www.cnblogs.com/1112zx/p/11664083.html