当前位置:网站首页>赚够钱回老家吗
赚够钱回老家吗
2022-06-25 06:38:00 【grace.free】
我认识一个朋友,诸葛十三,他的计划是存够一百万就回老家。
在2021年的5月20号他赚够了钱,如愿以偿的回到了老家。
回老家的他开了一个花卉养殖的小厂子,成本很小,平时雇一些附近的农民或者亲戚来帮他打理一下。
他主要负责的是销售问题,主要是通过网络渠道进行销售。
当然了,公司虽小,五脏俱全。公司有一个财务小姐姐。
这天十三叫来小姐姐说,你帮我统计一下最近工人的花费,看一下每个工资档位都有多少人。
十三公司工资档位一共分三个档500元/月,1000元/月,1500元/月。
因为大多数都是临时的,所以这个工资在一个小城镇还是比较合理的。
财务小姐姐经过一晚上的excel操作终于统计出来了,因为人口流动快,所以统计的很费劲。
第二天,小姐姐找到老板说,我要辞职,十三心中一惊,为什么呀?
小姐姐说,我在这小地方当财务,就想朝九晚五,轻轻松松,但是你让我统计这个东西,还要第二天就给你,我昨天通宵干到凌晨4点,都没睡觉,今天又来上班了。
经历北漂的十三深知这种感觉,于是十三就说,这种统计以后我帮你做,我曾经也是快做到技术CTO的人,我写一个程序帮你统计,怎么样,别走了嘛,好不容易找见一个信得过的财务。
在十三的软磨硬泡下,财务小姐姐决定不走了。
回到加的十三,找到了2年前上班时用的电脑,打开一看还好用,idea还能打开,泡上一杯枸杞茶,他开始写代码了。
一、重拾代码
经过了1个小时的努力,十三写出了第一版。
package ss;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/** * @author 木子的昼夜编程 */
public class Test {
public static void main(String[] args) {
// 1. 测试数据
List<Person> all= new ArrayList<>();
all.add(new Person("向东", 500));
all.add(new Person("红霞", 500));
all.add(new Person("红斌", 500));
all.add(new Person("红卫", 500));
all.add(new Person("红雄", 500));
all.add(new Person("向东", 1000));
all.add(new Person("建军", 1000));
all.add(new Person("继农", 1000));
all.add(new Person("继兵", 1000));
all.add(new Person("狗蛋", 1500));
all.add(new Person("文武", 1500));
all.add(new Person("小刚", 1500));
all.add(new Person("道明", 1500));
// 2. 分组 最后结构是{档位1:[人员],档位2:[人员]}
Map<Integer,List<Person>> map = new HashMap<>();
// 档位
Integer i500 = 500;
Integer i1000 = 1000;
Integer i1500 = 1500;
// 初始化Map
map.put(i500, new ArrayList<>());
map.put(i1000, new ArrayList<>());
map.put(i1500, new ArrayList<>());
// 遍历所有数据进行处理
for (int i = 0; i < all.size(); i++) {
Person person = all.get(i);
// 500档位
if (i500 == person.salary) {
map.get(i500).add(person);
}
// 1000档位
if (i1000 == person.salary) {
map.get(i1000).add(person);
}
// 1500档位
if (i1500 == person.salary) {
map.get(i1500).add(person);
}
}
// 输出结果
System.out.println(map);
}
}
class Person{
public Person(String name, Integer salary){
this.name = name;
this.salary = salary;
}
// 姓名
String name;
// 薪资
Integer salary;
@Override
public String toString() {
return "Person{" +
"name='" + name + '\'' +
", salary=" + salary +
'}';
}
}
读者朋友们,目测一下这个输出结果是什么。
你猜对了,输出结果是:{500=[], 1000=[], 1500=[]}
为什么说熟能生巧呢,一年没写代码了,十三忽略了,包装类型不能直接用“==”比较值。
经过修改:
package ss;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/** * @author 木子的昼夜编程 */
public class Test {
public static void main(String[] args) {
// 1. 测试数据
List<Person> all= new ArrayList<>();
all.add(new Person("向东", 500));
all.add(new Person("红霞", 500));
all.add(new Person("红斌", 500));
all.add(new Person("红卫", 500));
all.add(new Person("红雄", 500));
all.add(new Person("向东", 1000));
all.add(new Person("建军", 1000));
all.add(new Person("继农", 1000));
all.add(new Person("继兵", 1000));
all.add(new Person("狗蛋", 1500));
all.add(new Person("文武", 1500));
all.add(new Person("小刚", 1500));
all.add(new Person("道明", 1500));
// 2. 分组 最后结构是{档位1:[人员],档位2:[人员]}
Map<Integer,List<Person>> map = new HashMap<>();
// 档位
Integer i500 = 500;
Integer i1000 = 1000;
Integer i1500 = 1500;
// 初始化Map
map.put(i500, new ArrayList<>());
map.put(i1000, new ArrayList<>());
map.put(i1500, new ArrayList<>());
// 遍历所有数据进行处理
for (int i = 0; i < all.size(); i++) {
Person person = all.get(i);
// 500档位
if (i500.equals(person.salary)) {
map.get(i500).add(person);
}
// 1000档位
if (i1000.equals(person.salary)) {
map.get(i1000).add(person);
}
// 1500档位
if (i1500.equals(person.salary)) {
map.get(i1500).add(person);
}
}
// 输出结果
System.out.println(map);
}
}
class Person{
public Person(String name, Integer salary){
this.name = name;
this.salary = salary;
}
// 姓名
String name;
// 薪资
Integer salary;
@Override
public String toString() {
return "Person{" +
"name='" + name + '\'' +
", salary=" + salary +
'}';
}
}
注意看,比较用的是equals
{
500=
[Person{
name='向东', salary=500},
Person{
name='红霞', salary=500},
Person{
name='红斌', salary=500},
Person{
name='红卫', salary=500},
Person{
name='红雄', salary=500}],
1000=
[Person{
name='向东', salary=1000},
Person{
name='建军', salary=1000},
Person{
name='继农', salary=1000},
Person{
name='继兵', salary=1000}],
1500=
[Person{
name='狗蛋', salary=1500},
Person{
name='文武', salary=1500},
Person{
name='小刚', salary=1500},
Person{
name='道明', salary=1500}]
}
二、 老友来了
十三曾经北漂的时候认识了一个外号叫“李大明白”的人,李大明白由于房贷压力,所以没有离开北京。
五一假期,李大明白准备去找十三聊聊人生,于是坐车到了十三所在的镇上。
十三请李大明白吃了家常菜,大饼虾酱葱、清蒸梭子蟹、羊肚汤、火锅鸡。
那叫一个好吃呀。
李大明白说:你这现在挺悠闲呀,在家种种花,管管人,赚点儿养老的钱。
十三说:害!可别说了,我一年多没写代码了,昨天又执笔写代码了。
李大明白说:嗯?为啥呀,种花还要写代码吗?
十三说:害!那不是被财务小姐姐逼得吗?
李大明白说:什么?想当年北漂你就天天被财务小姐姐逼得搞NC问题,咋回来当老板还要被财务小姐姐逼着干活儿。
十三说:害,别说了,这不是看上财务小姐姐了,不想让她走,想培养一下感情,当了老板才发现,一个人过是真不好受呀。
李大明白说:哦,原来如此,有啥问题找我,毕竟我还在一线。
十三说:问题解决了,就是因为包装类型比较问题,你说这个Java的作者,好好地非得给基本类型搞一个包装类型,时间长不用就混乱了。
李大明白说:哈哈,想当初我刚毕业的时候,也犯过类似错误。
李大明白说:之所以有包装类型,我认为第一:Java是面向对象的编程语言,加包装类型是为了让基本数据类型也具有对象的特征。你像我们使用Collection的时候只能使用包装类型。
其次:包装类型还提供了一些基础类型没有的方法或功能,比如Integer.MAX_VALUE 获取int类型的最大值
Integer.max(int a,int b) 获取2个int类型数据的最大值、Integer.toHexString(int a) 10进制转16进制字符串等
十三说:对哦,好久不写代码,都忘了这些事情了,你一说 我想起来了,当时我当面试官的时候,还问过面试者关于包装类型的问题呢
李大明白说: 哦? 是吗,啥问题了,我现在也是高级开发了,也帮公司面试呢,下次我也问一下他们。
十三故作深沉的说:让我想想… 你随我来
李大明白跟着十三就进屋了,十三拿出了一个笔记本(纸质笔记本哦),翻了三五下,找到了以下代码:
/** * @author 木子的昼夜编程 */
public class AA {
public static void main(String[] args) {
Integer i1 = 100;
Integer i2 = 100;
Integer i3 = 200;
Integer i4 = 200;
System.out.println(i1==i2);
System.out.println(i3==i4);
}
}
问面试者,以下代码输出结果是什么?
李大明白会心一笑:哈哈,我知道你要考察什么。 这个应该输出true 、false
这里有个知识是:Integer i = 100; 编译后其实会变成:Integer i = Integer.valueOf(100);
我们看一下valueOf的方法:
//
public static Integer valueOf(int i) {
// 看i是否在指定范围内 如果在的话 就从缓存获取
// static final int low = -128;
// IntegerCache.high默认127 可以通过 VM参数:-XX:AutoBoxCacheMax=xx 进行制定
if (i >= IntegerCache.low && i <= IntegerCache.high)
// 为什么这里是这样取 因为下标只能从0开始 从0到 -IntegerCache.low(不包含) 下标都是负数
// 下标-IntegerCache.low对应的值是 0
return IntegerCache.cache[i + (-IntegerCache.low)];
// 新创建一个Integer
return new Integer(i);
}
我们在源码中可以看到如下代码:
// 初始化缓存
for(int k = 0; k < cache.length; k++)
cache[k] = new Integer(j++);
我们可以看到,默认情况下,数值在-128到127之间的数值都会从缓存获取。
所以我们例子中i1 == i2 结果是true , i3 == i4 结果是false
注意喽,这只是默认情况下,我们也说过,缓存的最大值是可以通过VM参数-XX:AutoBoxCacheMax=xx设置的,如果我们面试的时候能跟面试官聊到可以配置这点的话,面试官大概率会多问你一会儿,这样你被录取的概率就会更大。
比如我们设置一个400:
我们再执行刚才代码,就会输出2个true

十三说: 还是得李大明白,哈哈
两个人你一言我一语的聊着聊着已到深夜。
三、老友离别
天下没有不散的宴席,次日,李大明白要赶回北京的火车一大早起来,准备出发,十三拿了一个礼盒,里边装了几株多肉,希望给李大明白枯燥的北京生活增加一点绿意。
边栏推荐
- Following the last minor upgrade of nodemcu (esp8266)
- Ht513 I2S input 2.8W mono class D audio power amplifier IC
- 【ROS2】为什么要使用ROS2?《ROS2系统特性介绍》
- Kubernetes cluster dashboard & kuboard installation demo
- Americo technology launches professional desktop video editing solution
- TorchServe避坑指南
- Qcom--lk phase I2C interface configuration scheme -i2c6
- Grouped uitableview has 20px of extra padding at the bottom
- Astronomers may use pulsars to detect merged supermassive black holes
- The Rust Programming Language
猜你喜欢

Ht8513 single lithium battery power supply with built-in Dynamic Synchronous Boost 5W mono audio power amplifier IC solution

Uncaught TypeError: Cannot read properties of undefined (reading ‘prototype‘)

R & D thinking 07 - embedded intelligent product safety certification required

深入解析 Apache BookKeeper 系列:第三篇——读取原理

Navicat防止新建查询误删

Direct select sort and quick sort
![Analysis on the output, market scale and development status of China's children's furniture industry in 2020 and the competition pattern of children's furniture enterprises [figure]](/img/3a/e7a7ed1390664a6660112713266bdc.jpg)
Analysis on the output, market scale and development status of China's children's furniture industry in 2020 and the competition pattern of children's furniture enterprises [figure]

Ht513 I2S input 2.8W mono class D audio power amplifier IC

Single lithium battery 3.7V power supply 2x12w stereo boost audio power amplifier IC combination solution

Cve-2022-23131 - bypass SAML SSO authentication
随机推荐
'how do I create an enumeration with constant values in rust?'- How can I create enums with constant values in Rust?
有能力的人从不抱怨大环境!
【一起上水硕系列】Day 5
Comparison test of mono 120W high power class D power amplifier chip cs8683-tpa3116
Fastadmin cascade clear data
Cs8126t 3.1w mono ultra low EMI unfiltered class D audio power amplifier IC
聚类和分类的最基本区别。
Message queue table structure for storing message data
Drawing shp files using OpenGL
Ht513 I2S input 2.8W mono class D audio power amplifier IC
In a single-page app, what is the right way to deal with wrong URLs (404 errors)?
Non-contact infrared temperature measurement system for human body based on single chip microcomputer
Meta universe is over, Web 3.0 will be fooled again?
Americo technology launches professional desktop video editing solution
Blue Bridge Cup SCM module code (timer) (code + comments)
活动报名|Apache Pulsar x KubeSphere 在线 Meetup 火热来袭
Astronomers may use pulsars to detect merged supermassive black holes
アルマ / alchemy girl
Derivation of COS (a-b) =cosa*cosb+sina*sinb
keil debug查看变量提示not in scope