今天刚刚接触到java,首先学习了用idea打出九九乘法表,代码如下
public class Test1 {
public static void main(String[] args) {
for(int i=1;i<=9;i++){
for(int j =1;j<=i;j++){
System.out.print(i+"*"+j+"="+i * j +" ");
}
System.out.println( );
}
}
}
然后做了个美女选妃当然还没做完,代码如下:
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class BeautifulLadies {
void getLadies(){
List hights=new ArrayList<>();
List weights=new ArrayList<>();
hights.add(180);
hights.add(150);
hights.add(155);
weights.add(55);
weights.add(50);
weights.add(70);
System.out.println(hights);
System.out.println(weights);
getHightWeightAvg(hights,weights);
Map<String,Integer> hightweightAvg = getHightWeightAvg(hights, weights);
System.out.println(hightweightAvg);
boolean result = getResult(hightweightAvg);
if (result){
System.out.println(“是美女”);
}else{
System.out.println(“不是美女”);
}
}
Map<String,Integer> getHightWeightAvg(List hights,List weights){
int sumH=0;
for(int h:hights){
sumH=sumH+h;
}
int sumW=0;
for(int w:weights){
sumW=sumW+w;
}
System.out.println(“sumH:”+sumH);
System.out.println(“sumW:”+sumW);
int avgH=sumH/3;
int avgW=sumW/3;
Map<String,Integer> map=new HashMap<>();
map.put(“avgH”,avgH);
map.put(“avgW”,avgW);
return map;
}
boolean getResult(Map<String,Integer> map){
int avgH = map.get(“avgH”);
int avgW = map.get(“avgW”);
if(avgH>150 && avgW<60){
return true;
}else{
return false;
}
}
public static void main(String[] args) {
BeautifulLadies beautifulLadies=new BeautifulLadies();
beautifulLadies.getLadies();
}
}
简单来说是创建对象,然后从中筛选出符合条件的
还有就是java的数据类型,分为基础数据类型和引用数据类型
基础数据类型有:
byte(字节)
shot(短整型)
int(整型)
long(长整型)
float(浮点型)
double(双精度)
char(字符型)
boolean(布尔型)
引用数据类型分3种:类,接口,数组;