会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 133472个问题

import java.util.Scanner;
public class salaryCalculator {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        System.out.println("**********我的薪水计算器********");
        System.out.println("1、输入88.退出程序。 \n2、输入66,计算下一个年薪");
        while(true){
            System.out.println("请输入你的月薪");
            int monthSalary = s.nextInt();
            System.out.println("每年是几个月的薪水");
            int months = s.nextInt();
            int yearSalary = monthSalary*months;
            System.out.println("你的年薪是"+yearSalary);
            if (yearSalary>200000){
                System.out.println("恭喜你超越98%的人,大佬");
            }
                else if (yearSalary>100000){
                    System.out.println("恭喜你超越90%的人");
                }
            }

            System.out.println("输入88,退出系统;输入66,进行下一个用户");
            int comm = s.nextInt();
            if (comm == 88){
                System.out.println("退出系统!");
                break;
            }
            if (comm == 66){
                System.out.println("继续计算下一个用户");
                continue;
            }


        }

    }

同样代码,我出了这个问题

image.png

JAVA 全系列/第一阶段:AI驱动的JAVA编程/控制语句、方法、递归算法 1501楼
WEB前端全系列/第一阶段:HTML5+CSS3模块/CSS应用技巧 1505楼
Python 全系列/第二十阶段:数据分析-数据管理/Pandas基本使用 1506楼
JAVA 全系列/第四阶段:数据库与AI协同技术实战/SQL 语言 1507楼
Python 全系列/第二十二阶段:Python数据分析项目/二手车价格预测 1508楼
Python 全系列/第一阶段:Python入门/序列 1509楼
JAVA 全系列/第五阶段:网页编程和设计/CSS3(旧) 1511楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/IO 流技术(旧) 1512楼
Python 全系列/第二十一阶段:数据分析-统计分析/参数估计 1513楼

问题描述:文件中显示的还是乱码,编译不报错


代码如下:

import java.io.BufferedInputStream;

import java.io.BufferedOutputStream;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.ObjectInputStream;

import java.io.ObjectOutputStream;


public class TestPerson {

public static void main(String[] args) {

write();

read();

}

public static void read() {

//创建对象流对象

ObjectInputStream ois=null;

try {

ois = new ObjectInputStream(new FileInputStream("D:\\object11.txt"));

//读取数据

System.out.println(ois.readBoolean());

System.out.println(ois.readInt());

System.out.println(ois.readDouble());

System.out.println(ois.readUTF());

//System.out.println(ois.readChar());

Person p=(Person)ois.readObject();

System.out.println(p);

} catch (FileNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (ClassNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}finally {

if(ois!=null) {

try {

ois.close();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

}

public static void write() {

//创建对象流对象

ObjectOutputStream oos=null;

try {

oos = new ObjectOutputStream(new FileOutputStream("D:\\object11.txt"));

//写入数据

oos.writeBoolean(true);

oos.writeInt(999);

oos.writeDouble(888.88);

oos.writeUTF("朝辞白帝彩云间,千里江陵一日还");

//oos.writeChars("helloworldjava");

oos.writeObject(new Person("临江仙", 20));

//oos.flush();

} catch (FileNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}finally {

if(oos!=null) {

try {

oos.close();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

}

}



运行结果如下:




360截图20191213232837666.jpg






JAVA 全系列/第二阶段:JAVA 基础深化和提高/IO 流技术(旧) 1514楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637