public class InputTest {
public static void main(String[] args) {Scanner in = new Scanner(System.in); //构造一个Scanner对象,并于标准输入流关联System.out.print("What's your name?");String name = in.nextLine(); //输入一行System.out.print("How old are you?");int age = in.nextInt(); //输入一个整型数值System.out.println("Hello, " + name + ". Next year, you'll be" + (age + 1));}
}
package corejava;import java.io.FileNotFoundException;import java.io.IOException;import java.io.PrintWriter;import java.nio.file.Paths;import java.util.*;public class FileInOutput {public static void main(String[] args) throws FileNotFoundException,IOException {
//PrintWriter out = new PrintWriter("F://Java//corejava//book.txt"); 绝对路径写法PrintWriter out = new PrintWriter("book.txt"); //相对路径写法out.println("code complete");out.println("Spring in action");out.close();//Scanner in = new Scanner(Paths.get("F://Java//corejava//book.txt"));Scanner in = new Scanner(Paths.get("book.txt"));String book1 = in.nextLine();String book2 = in.nextLine();in.close();System.out.println("book1:" + book1);System.out.println("book2:" + book2);System.out.println(System.getProperty("user.dir")); //Java虚拟机启动路径为F:/Java/corejava/ 因此上面的绝对路径和相对路径写法是等价的。}
}3.8 控制流程
1)块(即复合语句),是指由以对花括号括起来的若干简单的Java语句。2)块确定了变量的作用域3)一个块可以嵌套在另一个块中,但是不能在两个嵌套的块中声明同名的变量。
import java.math.BigInteger;
public class BigIntegerTest {3.10 数组public static void main(String[] args) {BigInteger a = BigInteger.valueOf(5);BigInteger b = BigInteger.valueOf(6);BigInteger c = a.add(b);BigInteger d = a.multiply(b);System.out.println(c);System.out.println(d);}}
public class CommandLineArgs {
public static void main(String[] args) {// TODO Auto-generated method stubSystem.out.println(args.length);for(String s:args){System.out.println(s);}
}}java CommandLineArgs -jrr tmac -lbj
import java.util.Arrays;public class SortTest {
public static void main(String[] args) {// TODO Auto-generated method stubint[] a = {1,3,2,5,9,7};System.out.println(Arrays.toString(a));Arrays.sort(a); //采用优化的快速排序法,对数组进行排序System.out.println(Arrays.toString(a));}
}
Arrays.binarySearch
新闻热点
疑难解答