「java两个代码输出」java输入两个数和运算符

博主:adminadmin 2023-01-06 16:12:10 717

今天给各位分享java两个代码输出的知识,其中也会对java输入两个数和运算符进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

求JAVA高手,输出两段代码

public class MyDate {

    private int year;

    private int month;

    private int date;

    public MyDate(int year, int month, int date) {

        this.year = year;

        this.month = month;

        this.date = date;

    }

    public MyDate() {

    }

    public int getYear() {

        return year;

    }

    public void setYear(int year) {

        this.year = year;

    }

    public int getMonth() {

        return month;

    }

    public void setMonth(int month) {

        this.month = month;

    }

    public int getDate() {

        return date;

    }

    public void setDate(int date) {

        this.date = date;

    }

    @Override

    public String toString() {

        return new StringBuilder().append(year).append("-").append(month).append("-").append(date).toString();

    }

    public static void main(String[] args) {

        MyDate myDate = new MyDate();

        myDate.setYear(2015);

        myDate.setMonth(9);

        myDate.setDate(16);

        System.out.println(myDate);

        System.out.println(new MyDate(2015, 9, 16));

    }

}

public static void main(String[] args) {

    try {

        File file = new File("D:\\farrago.txt");

        File descFile = new File("D:\\out.txt");

        InputStream is = new FileInputStream(file);

        OutputStream os = new FileOutputStream(descFile);

        byte[] buffer = new byte[1024];

        int n;

        while ((n = is.read(buffer)) != -1) {

            os.write(buffer, 0, n);

        }

        is.close();

        os.flush();

        os.close();

    } catch (Exception e) {

        // TODO: handle exception

    }

}

JAVA 两个代码输出结果不一样?

下面那个read方法调用了两次,当然会不一样。

改成:

int readData;

while(true)

{

if((readData=fis.read())==-1)

break;

System.out.println(readData);

}

JAVA 为什么这两个输出结果不一样?

第一个图里面在system.out.println(fis.read())又调用了一次,加上前面if(fis.read()==-1)那次,相当于一次循环调用了两次。

所以输出的是b,d,f和读到末尾的-1

java两个代码输出的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java输入两个数和运算符、java两个代码输出的信息别忘了在本站进行查找喔。