44< head >
55 < meta charset ="utf-8 " />
66 < title > | Bigfish</ title >
7- < meta name ="author " content ="John Doe " />
8- < meta name ="description " content ="" />
9- < meta name ="keywords " content ="" />
7+ < meta name ="author " content ="Bigfish " />
8+ < meta name ="description " content ="个人学习网站,记录知识 " />
9+ < meta name ="keywords " content ="笔记 " />
1010 < meta
1111 name ="viewport "
1212 content ="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0 "
@@ -71,11 +71,6 @@ <h2>LOADING</h2>
7171 < span >  Home</ span >
7272 </ a >
7373
74- < a href ="/about ">
75- < i class ="fa-solid fa-id-card fa-fw "> </ i >
76- < span >  About</ span >
77- </ a >
78-
7974 < a href ="/archives ">
8075 < i class ="fa-solid fa-box-archive fa-fw "> </ i >
8176 < span >  Archives</ span >
@@ -109,15 +104,6 @@ <h2>LOADING</h2>
109104 </ div >
110105 </ a >
111106
112- < a href ="/about ">
113- < div class ="item ">
114- < div style ="min-width: 20px; max-width: 50px; width: 10% ">
115- < i class ="fa-solid fa-id-card fa-fw "> </ i >
116- </ div >
117- < div style ="min-width: 100px; max-width: 150%; width: 20% "> About</ div >
118- </ div >
119- </ a >
120-
121107 < a href ="/archives ">
122108 < div class ="item ">
123109 < div style ="min-width: 20px; max-width: 50px; width: 10% ">
@@ -170,7 +156,11 @@ <h1></h1>
170156 </ div >
171157
172158 < div class ="content " v-pre >
173- < h3 id ="测试文章 "> < a href ="#测试文章 " class ="headerlink " title ="测试文章 "> </ a > 测试文章</ h3 > < pre > < code class ="language-java "> import java.util.Arrays;
159+ < h3 id ="java基础 "> < a href ="#java基础 " class ="headerlink " title ="java基础 "> </ a > java基础</ h3 > < p > 记录学习中一些不熟悉的内容</ p >
160+ < span id ="more "> </ span >
161+
162+ < h2 id ="练习1-杨辉三角 "> < a href ="#练习1-杨辉三角 " class ="headerlink " title ="练习1:杨辉三角 "> </ a > 练习1:杨辉三角</ h2 > < pre > < code class ="language-java ">
163+ import java.util.Arrays;
174164
175165//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
176166// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
@@ -200,7 +190,118 @@ <h3 id="测试文章"><a href="#测试文章" class="headerlink" title="测试
200190 }
201191 }
202192}
203- ...
193+ </ code > </ pre >
194+ < p > 在写杨辉三角案例的时候发现了一个二维数组初始化的问题。</ p >
195+ < p > 如果只初始化行的话, 二维的数组默认值是null</ p >
196+ < pre > < code class ="language-java "> int numberOfRows = 5; // 例如5行
197+ int[][] yangHuiTriangle = new int[numberOfRows][]; // 只初始化行
198+ yangHuiTriangle[0][0] = 1;
199+ </ code > </ pre >
200+ < p > 如果不初始化就进行赋值的话就会报错</ p >
201+ < pre > < code class ="language-java "> Exception in thread "main" java.lang.NullPointerException: Cannot store to int array because "yangHuiTriangle[0]" is null
202+ at Main.main(Main.java:10)
203+ </ code > </ pre >
204+ < p > 所以必须初始化之后在进行赋值</ p >
205+ < pre > < code class ="language-java "> int numberOfRows = 5; // 例如5行
206+ int[][] yangHuiTriangle = new int[numberOfRows][]; // 只初始化行
207+ yangHuiTriangle[0] = new int[1];
208+ yangHuiTriangle[0][0] = 1;
209+ </ code > </ pre >
210+ < h2 id ="随机数 "> < a href ="#随机数 " class ="headerlink " title ="随机数 "> </ a > 随机数</ h2 > < p > 在java中有常见的两种生成随机数的方法是Math.random() 和java.util.Random类</ p >
211+ < h3 id ="1-基本用法 "> < a href ="#1-基本用法 " class ="headerlink " title ="1. 基本用法 "> </ a > 1. 基本用法</ h3 > < h3 id ="Math-random-方法 "> < a href ="#Math-random-方法 " class ="headerlink " title ="Math.random() 方法 "> </ a > < code > Math.random()</ code > 方法</ h3 > < p > 功能: 生成[0.0,1.0)范围内的double类型的伪随机数,线程安全的</ p >
212+ < p > 语法:Math.ranndom()</ p >
213+ < pre > < code class ="language-java "> // 0-100
214+ int randomInt = (int)(Math.random() * 100)
215+
216+ // 1-30
217+ int randomInt = (int)(Math.random() * 30) + 1
218+
219+ // 生成 [5, 20] 的随机整数(通用公式)
220+ int min = 5, max = 20;
221+ int randomInt = (int) (Math.random * (max - min + 1)) + min
222+ </ code > </ pre >
223+ < h3 id ="java-util-Random-类 "> < a href ="#java-util-Random-类 " class ="headerlink " title ="java.util.Random 类 "> </ a > < code > java.util.Random</ code > 类</ h3 > < h4 id ="1-基本用法-1 "> < a href ="#1-基本用法-1 " class ="headerlink " title ="1. 基本用法 "> </ a > 1. 基本用法</ h4 > < ul >
224+ < li > < strong > 功能</ strong > :生成多种类型的随机数(整数、浮点数、布尔值等)。线程不安全</ li >
225+ < li > < strong > 语法</ strong > :</ li >
226+ </ ul >
227+ < pre > < code class ="language-java "> Random random = new Random(); // 默认种子为系统时间
228+ Random seededRandom = new Random(123L); // 指定种子
229+ </ code > </ pre >
230+ < h4 id ="2-核心方法 "> < a href ="#2-核心方法 " class ="headerlink " title ="2. 核心方法 "> </ a > 2. 核心方法</ h4 > < table >
231+ < thead >
232+ < tr >
233+ < th align ="left "> 方法</ th >
234+ < th align ="left "> 返回值</ th >
235+ < th align ="left "> 范围</ th >
236+ </ tr >
237+ </ thead >
238+ < tbody > < tr >
239+ < td align ="left "> < code > nextInt()</ code > </ td >
240+ < td align ="left "> < code > int</ code > </ td >
241+ < td align ="left "> 所有可能的 < code > int</ code > 值</ td >
242+ </ tr >
243+ < tr >
244+ < td align ="left "> < code > nextInt(int bound)</ code > </ td >
245+ < td align ="left "> < code > int</ code > </ td >
246+ < td align ="left "> < code > [0, bound)</ code > </ td >
247+ </ tr >
248+ < tr >
249+ < td align ="left "> < code > nextDouble()</ code > </ td >
250+ < td align ="left "> < code > double</ code > </ td >
251+ < td align ="left "> < code > [0.0, 1.0)</ code > </ td >
252+ </ tr >
253+ < tr >
254+ < td align ="left "> < code > nextBoolean()</ code > </ td >
255+ < td align ="left "> < code > boolean</ code > </ td >
256+ < td align ="left "> < code > true</ code > 或 < code > false</ code > </ td >
257+ </ tr >
258+ < tr >
259+ < td align ="left "> < code > nextLong()</ code > </ td >
260+ < td align ="left "> < code > long</ code > </ td >
261+ < td align ="left "> 所有可能的 < code > long</ code > 值</ td >
262+ </ tr >
263+ </ tbody > </ table >
264+ < h2 id ="练习2-创建一个长度为6的int型数组,要求数组元素的值都在1-30之间,-且是随机赋值。同时,要求元素的值各不相同。 "> < a href ="#练习2-创建一个长度为6的int型数组,要求数组元素的值都在1-30之间,-且是随机赋值。同时,要求元素的值各不相同。 " class ="headerlink " title ="练习2:创建一个长度为6的int型数组,要求数组元素的值都在1-30之间, 且是随机赋值。同时,要求元素的值各不相同。 "> </ a > 练习2:创建一个长度为6的int型数组,要求数组元素的值都在1-30之间, 且是随机赋值。同时,要求元素的值各不相同。</ h2 > < pre > < code class ="language-java "> int[] arr = new int[6];
265+
266+ for(int i = 0; i < arr.length; i++){
267+ for(int j = 0; j < i; j++){
268+ if(arr[i] == arr[j]){
269+ i--;
270+ break;
271+ }
272+ }
273+ }
274+ </ code > </ pre >
275+ < h3 id ="练习3-遍历扑克牌 "> < a href ="#练习3-遍历扑克牌 " class ="headerlink " title ="练习3:遍历扑克牌 "> </ a > 练习3:遍历扑克牌</ h3 > < pre > < code class ="language-java "> import java.util.Arrays;
276+
277+
278+ public class Main {
279+ public static void main(String[] args) {
280+ String[] suit = new String[]{"♣", "♦", "♥", "♠"};
281+ String[] scores = new String[]{"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"};
282+ String[] poker = new String[56];
283+
284+ int total = 0;
285+ for (int i = 0; i < suit.length; i++) {
286+ for (int j = 0; j < scores.length; j++) {
287+ poker[total++] = suit[i] + scores[j];
288+ }
289+ }
290+
291+ poker[total++] = "Big Joker";
292+ poker[total++] = "Little Joker";
293+
294+
295+ for (int i = 0; i < total; i++) {
296+ if (i % 13 == 0 && i != 0) {
297+ System.out.println();
298+ }
299+ System.out.print(poker[i] + " ");
300+
301+ }
302+
303+ }
304+ }
204305</ code > </ pre >
205306
206307 </ div >
@@ -221,7 +322,7 @@ <h3 id="测试文章"><a href="#测试文章" class="headerlink" title="测试
221322 < span id ="footer-icon ">
222323 < i class ="fa-solid fa-font-awesome fa-fw "> </ i >
223324 </ span >
224- @John Doe
325+ @Bigfish
225326 </ div >
226327 < div >
227328 Based on the < a target ="_blank " rel ="noopener " href ="https://hexo.io "> Hexo Engine</ a > &
0 commit comments