Java中的基本程序设计和结构
控制台输入输出
Java代码
1)Scanner in = new Scanner(System.in);
System.out.println("What is your name?");
String name = in.nextLine();
System.out.println("How old are you?");
int age = in.nextInt();
in.next(); //读一个单词
2)Console cons = System.console();
String userName = cons.readLine("User Name: ");
char[] password = cons.readPassword("Password: "); // 密码处理之后马上用填充值覆盖数组元素——安全
1)Scanner in = new Scanner(System.in);
System.out.println("What is your name?");
String name = in.nextLine();
System.out.println("How old are you?");
int age = in.nextInt();
in.next(); //读一个单词
2)Console cons = System.console();
String userName = cons.readLine("User Name: ");
char[] password = cons.readPassword("Password: "); // 密码处理之后马上用填充值覆盖数组元素——安全 3)格式化输出
System.out.printf("%,.2f", 10000.0/3.0); ==> 3,333.33
文件的输入输出
1)Scanner in = new Scanner(new File("myfile.txt")); // 构造一个从给定文件读取数据的Scanner
2)Scanner in = new Scanner(String data); // 构造一个从给定字符串读取数据的Scanner
3)PrintWriter out = new PrintWriter("myfile.txt"));
控制流程
1)flag: ... break flag;
大数值
1)BigInteger
2)BigDecimal
数组
1)简单打印System.out.println(Arrays.toString(array));
2)数组拷贝Arrays.copyOf/System.arraycopy(from, fromIndex, to, toIndex, count);
3)数组排序Arrays.sort(array);
4)int r = (int)(Math.random() * n) [0, n-1]随机整数
5)for(double[] row : array)
for(double value: row)
do something with value
6)二维数组快速打印System.out.println(Arrays.deepToString(array));
7)不规则数组
int[][] odds = new int[NMAX + 1][]
for(int n = 0; n <= NMAX; n++)
odds[n] = new int[n+1];
西安达内基础阶段实训主题分别是,Unix开发环境,Java语言基础,Java面向对象,JDK核心API...实训内容分别是,Unix系统原理、Unix开发环境、Unix常用命令。算法基础、常用数据结构、企业编程规范。面向对象特性:封装、继承、多态等。语言核心包、异常处理、常用工具包、集合框架等。
文章转自www.xatarena.cn