摘要: Scanner in = new Scanner(System.in); String s; s = in.next(); System.out.println(s); 首先,next和nextLine都可以读入,next()的规则是读到第一个空格就停止,这个空格是广义上的空格,包括Tab或者换行。 阅读全文
posted @ 2024-01-16 13:14 绿皮玻璃 阅读(111) 评论(0) 推荐(0)
摘要: | 基本类型 | 包裹类型 | boolean | Boolean | | char | Character | | byte | Byte | | short | Short | | int | Integer | | long | Long | | float | Float | | doubl 阅读全文
posted @ 2024-01-15 20:27 绿皮玻璃 阅读(27) 评论(0) 推荐(0)
摘要: char a = 'A'; System.out.println('a'-'A'); char b = (char)(a+'a'-'A'); System.out.println(b); 此时输出32 a;因为Java字符可以运算,但是运算后就不再是字符,而是数字,字符运算规则是根据unicode。 阅读全文
posted @ 2024-01-15 19:51 绿皮玻璃 阅读(77) 评论(0) 推荐(0)
摘要: int a = 10; System.out.println(a+1 +"字符串拼接"+a+1); 此时输出 :11字符串拼接101 为什么? 这是因为在Java里,如果数字前没有字符拼接,那么先进行数字运算,就像第一个a+1,先得出11。 但是第二个a+1前有字符拼接,那么第二个a+1就会被Jav 阅读全文
posted @ 2024-01-15 13:10 绿皮玻璃 阅读(254) 评论(0) 推荐(0)
摘要: int[] a = {1,2,3}; int[] b = a; System.out.println(a == b); 此时输出true int[] a = {1,2,3}; int[] b = {1,2,3}; System.out.println(a == b); 此时输出为false 这是因为 阅读全文
posted @ 2024-01-15 12:33 绿皮玻璃 阅读(40) 评论(0) 推荐(0)
摘要: import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); out: 阅读全文
posted @ 2024-01-14 12:51 绿皮玻璃 阅读(47) 评论(0) 推荐(0)
摘要: import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("请输入数字:") 阅读全文
posted @ 2024-01-13 16:18 绿皮玻璃 阅读(63) 评论(0) 推荐(0)