赞
踩
目录
数据的输入:
- Scanner sc = new Scanner(System.in);
- int n = sc.nextInt();
-
- //不将空格看做是两个字符串的间隔,而是看作字符串的一部分,
- //返回时,它作为String类型一并返回。
- nextLine()
数据的输出:
(1)print()方法:实现不换行的数据输出;
(2)println()方法:与上面方法的差别是输出数据后将换行。
(3)printf()方法:带格式描述的数据输出。该方法包含两个参数,第一个参数中给出输出格式的描述,第2个参数为输出数据,其中,输出格式描述字符串中需要安排与输出数据对应的格式符。
常用格式符包括:%d代表十进制数;%f代表浮点数;%e代表科学表示法的指数位数;%n代表换行符;%x代表十六进制数;%s代表字符串。
- while(循环条件表达式){
- 语句块
- }
- do{
- 语句块
- }
- while(条件表达式);
- //遍历循环
- for(int i;i<10;i++){
- 语句块
- }
-
- //增强型循环
- for (循环变量类型 循环变量名称 : 要被遍历的对象){
- 循环体
- }
-
- for(int i:score){增强型for是把score中的元素依次赋给i
- if(i>max) max=i;
- if(i<min) min=i;
- sum += i;
- }
int[] n = new int[5];
输入数组
- Scanner sc = new Scanner(System.in);
- int n = sc.nextInt();
- int f[] = new int[n];
- for(int i=0;i<n;i++){
- f[i] = sc.nextInt();
- }
int[][] n = new int [4][3];
输入数组
- Scanner sc = new Scanner(System.in);
- int n = sc.nextInt();
- int i, j;
- int[][] x = new int[n + 1][n + 1];
- for (i = 0; i < n; i++)
- for (j = 0; j <= i; j++)
- x[i][j] = sc.nextInt();
- //对数组元素从小到大排序
- Arrays.sort(int[] a)
- //根据ascii码取得其对应的字符
- char(int)
-
- //返回指定索引处字符串索引范围从0到length()-1
- charAt()
-
- //将字符串转换为字符数组
- str.toCharArray()
-
- //将整型数据Integer转换为基本数据类型int
- Integer.parseInt
-
- //返回int变量的二进制表示的字符串
- Integer.toBinaryString(i);
-
- //把对象转成字符串
- to String()
-
- //将int变量i转换成字符串
- String.valueOf(int i)
- String string = String.valueOf(int i);
-
- //判断str中是否有子字符串,有则返回true,没有则返回false
- str.contains
-
- //替换全部字符串
- string.replaceAll
-
- //截取父字符串的某一部分
- substring()
-
- //字符串常规类型格式化的两种重载方式
- String.format()
-

- //返回num的绝对值
- Math.abs(num)
-
- //求底数的次方
- Math.pow(底数,几次方)
-
- //求a的3次方
- Math.pow(a,3)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。