Java学习笔记(持续更新ing)

版权声明:本文为原创文章QWQ,如果有错误欢迎指正,转载请注明作者且附带网址 https://blog.csdn.net/Mercury_Lc/article/details/82829872

1、在读入字符串时:    str = sc.nextLine();     //读入一行
                                    str = sc.next();   // 只是读入字符串

2、在结构体的表示中用类来表示。

//down的地址https://blog.csdn.net/fyp19980304/article/details/80448060
方法一:把要存储的数据设为私有变量,然后另写函数对其进行读写,set()和get()
 
public  class Test
{
    private int x;
    private int y;
    public int getX() {
        return x;
    }
    public void setX(int x) {
        this.x = x;
    }
    public int getY() {
        return y;
    }
    public void setY(int y) {
        this.y = y;
    }
}

方法二: 把要存储的数据设为public变量,在其他主函数类中直接访问修改。
 
class Supply implements Comparable<Supply>{
	int number;
	int max;
	int spend;
}

猜你喜欢

转载自blog.csdn.net/Mercury_Lc/article/details/82829872
今日推荐