大數(shù)據(jù)
BigInteger:用valueOf方法將普通數(shù)值轉(zhuǎn)化為大數(shù)值,但它也無法直接使用算術(shù)運(yùn)算符(如+、*),需要使用add和multiply來運(yùn)算。
? ? ? ? ? ? ?BigInteger a=BigInteger.valueOf(100)
? ? ? ? ? ? ?BigInteger c=a.add(b)相當(dāng)于c=a+b
? ? ? ? ? ? ?BigInteger d=c.multioly(b)相當(dāng)于d=c*b
Scanner in=new Scanner(System.in);
System.out.print("How many number do you need to draw");
int k=in.nextInt();
System.out.print("What is the highest number you can draw?");
int n=in.nextInt();
BigInteger lotteryOdds=BigInteger.valueOf(1);
for(int i=1;i<=k;i++)
lotteryOdds=lotteryOdds.multiply(BigInteger.valueOf(n-i+1)).divide(BigInteger.valueOf(i));
System.out.println("Your odds are 1 in"+lotteryOdds+".Good luck!");
數(shù)組
int[] a=new int[100]
把數(shù)組控制到五十萬以下。
引用類型的只記住地址。
基本類型的拷貝為深拷貝,引用類型的拷貝為淺拷貝,淺拷貝指數(shù)組用一個(gè)內(nèi)存,深拷貝則是不同的內(nèi)存。
面向?qū)ο蟪绦蛟O(shè)計(jì)(OOP)
類:對(duì)事物描述的定義
靜態(tài)方法是類方法,被所有對(duì)象共享。
隨機(jī)生成數(shù)字:
Scanner in=new Scanner(System.in);
? System.out.print("How many numbers do you need to draw?");
? int k=in.nextInt();
? System.out.print("What is the highest number you can draw?");
int n=in.nextInt();
int[] numbers=new int[n];
for(int i=0;i<numbers.length;i++)
numbers[i]=i+1;
int[] result=new int[k];
for(int i=0;i<result.length;i++){
?int r=(int)(Math.random()*n);
result[i]=numbers[r];
numbers[r]=numbers[n-1];
n--;
? }
?Arrays.sort(result);
System.out.println("Bet the following combination.It will make you rich!");
for(int r:result)
System.out.println(r);
顯示時(shí)間
System.out.println(LocalDate.of(1999, 12, 12));
LocalDate newYearsEve=LocalDate.of(1999, 12, 12);
int year=newYearsEve.getYear();
int month=newYearsEve.getMonthValue();
int day=newYearsEve.getDayOfMonth();
System.out.println(LocalDate.now());
LocalDate aThousandDaysLater=newYearsEve.plusDays(100000);
year=aThousandDaysLater.getYear();
month=aThousandDaysLater.getMonthValue();
day=aThousandDaysLater.getDayOfMonth();
System.out.println(aThousandDaysLater);
LocalDate date=LocalDate.now();
int month=date.getMonthValue();
int today=date.getDayOfMonth();
date=date.minusDays(today-1);
DayOfWeek weekday=date.getDayOfWeek();
int value=weekday.getValue();
System.out.println("Mon Tue Wed Thu Fri Sat Sun");
for(int i=1;i<value;i++)
System.out.print("? ? ");
while(date.getMonthValue()==month)
{
System.out.printf("%3d",date.getDayOfMonth() );
if(date.getDayOfMonth()==today)
System.out.print("*");
else
System.out.print(" ");
date=date.plusDays(1);
if(date.getDayOfWeek().getValue()==1)
System.out.println();
}
if(date.getDayOfWeek().getValue()!=1)
System.out.println();
Mon Tue Wed Thu Fri Sat Sun
? 1? ? 2? ? 3? ? 4? ? 5? ? 6? ? 7
? 8? ? 9? 10? 11? 12? 13? 14
15? 16? 17? 18* 19? 20? 21
22? 23? 24? 25? 26? 27? 28
29? 30? 31
域:field(屬性)
構(gòu)造方法:constructor
class Employee
{
private String name;
private double salary;
private LocalDate hireDay;
構(gòu)造器與類同名
每個(gè)類默認(rèn)有一個(gè)構(gòu)造器
構(gòu)造器沒有返回值
構(gòu)造器和new一起調(diào)用
構(gòu)造器可以有0個(gè)、1個(gè)或多個(gè)參數(shù)
不要再構(gòu)造器里定義與實(shí)例域同名的局部變量