看视频学JAVA记录暑假生活

昨晚开始注册的博客,本来想把昨晚学到的知识整理一遍的,可是要隔一天才能发表博文,刚学java,跟着马士兵的视频学,一下是这两天记录的代码以及自己出现过的问题。
public class person{ //一般的类名首字母大写,方法名首字母都是小写,而且遵守驼峰书写格式
int id;
int age;
person(int id_,int age_){
id = id_;
age = age_;
}
public static void main(String args[]){
person tom = new person(1,25);
person pp = new person(1,20); //一般已经定义了方法,要                              按照定义来书写不能出现                              空参;
System.out.println("tom的资料为:"+tom.id+"、"+tom.age);
System.out.println("pp的资料为:"+tom.id+"、"+tom.age);
}
}

//switch中几种case输出相同内容,注意类名不能出现与关键字一样
public class aboutswitch {
public static void main(String args[]){
int i = 0;
switch (i)
{
case 0:
case 1:
case 2:
System.out.print("C");
break;
case 3:
System.out.print("B");
break;
default:
System.out.print("ZZ");
break;
}
}
}


//break 与continue 之间的区别
//求出101-200之内的所有质数
public class primenumber{
public static void main(String[] args){
for(int i=101;i<=200;i+=2){
boolean f = true;
for(int j=2;j<=i;j+=2){
if(i%j==0)
f=true;
break; //跳出循环,只能跳出一层,即最近的for循环
}
if(!f){continue;} //跳过一次,继续循环下去
System.out.print(" "+i);
}
}
}


class Point{
double x,y,z;

Point(double x_,double y_, double z_){
x = x_;
y = y_;
z = z_;
}

void setX(double x_){
x = x_;
}

void setY(double y_){
y = y_;
}

void setZ(double z_){
z = z_;
}

public double getDistance(Point p){
return (x - p.x)*(x - p.x) + (y - p.y)*(y - p.y) + (z - p.z)*(z - p.z);
}
}

public class TestPoint{
public static void main(String args[]){
Point p=new Point(3.0,3.0,3.0);
Point p1=new Point(0.0,0.0,0.0);
System.out.println(p.getDistance(p1));
p.setX(4.0);
System.out.println(p.getDistance(p1));
}
}

一天的学习快结束了,赶快回去洗澡玩玩睡觉了...以后再回首
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值