1、计算一组有多少个术语个数
int 名称=要计算的组名.length
public class SimpleArray {
public static void main(String[]args){
String[] wordListone={
"24/7","nmultiTier","30000 foot","B-to-B","win-win","front-end","web-based"};
String[] wordListtwo={
"empowered","sticky","value-added","oriented","centric"};
int[] wordListthree={
1,3,4,5,6};
int oneLength=wordListone.length;//计算一组有多少个
int twoLength=wordListtwo.length;
int threeLength=wordListthree.length;
System.out.println(oneLength);
System.out.println(twoLength);
System.out.println(threeLength);
}
}
2、产生随机数字
产生随机数字的结构:数值类型 变量名称=(数值类型)(Math.random())
PS:直接产生的数值会介于0~1之间的小数所以可以进行转换
public class Random {
public static void main(String[]args){
int c=(int)Math.random();//转换,将double类型转换为int类型
double x=Math.random();//产生一个随机数,仅仅会介于0和1之间
int y=5;
int z=(int)(x*y);//随机数与定义的数字相乘,转换
System.out.println(c);
System.out.print(z);
}
}
3、数组
一、一般数组
一般数组中的各种操作
public class PracticeNormalClass1 {
public static void main(String[]args){
String [] myList=new String[2];//定义普通数组
System.out.println(myList);
String s=new String("nihao");
myList[0]=s; //将s赋予普通数组第一个位置
String s1=new String("a");
myList[1]=s1;
int size=myList.length; //计算这个普通数组的大小
System.out.println(size);
String s2=myList[1]; //获取myList中1位置的值
System.out.println(s2);
myList[1]=null; //移除myList中1位置的值
boolean b=false; //判断某个特定元素是否在数组中
for(String item:myList){
if