sysout或Sysout+ Alt 和 /即可
System.out.println(); System.out.printf("\n");
System.out.print(); System.out.printf();
int d; System.out.printf(“%4d”,d); System.out.printf(“%-4d”,d); 输出的d是带有缩进的,若d前面有符号,则在输出前面空4个字节。 若d后面有符号,则在输出后面空4个字节。
小题一:从1开始到100,输出被三整除或者被七整除的数字(每行五个数,超出需要换行) 法一:
int count=0; for (int i=1;i<=100;i++){ if( i%3==0 || i%7==0){ if(i/10 < 1) { System.out.printf(" "); } System.out.printf(" %d",i); count++; } if(count==5) { System.out.println(); count=0; } }法二:
int count=0; for (int i=1;i<=100;i++){ if( i%3==0|| i%7==0){ System.out.printf("%4d",i); count++; } if(count==5) { System.out.println(); count=0; } }输出结果
小题二:从100开始输出52个数字,被三整除或者被七整除。(每行5个数) 法一:
int count=0,j=0; for (int i=100;;i++){ if( i%3==0|| i%7==0){ System.out.printf("%4d",i); count++; j++; } if(count==5) { System.out.println(); count=0; } if(j==52) { break; } }法二:
int count=0,j=0,i=100; while(j<=52){ if( i%3==0|| i%7==0){ System.out.printf("%4d",i); count++; j++; } if(count==5) { System.out.printf("\n"); count=0; } i++; } }法一:
int sum=1; int flag=1; for(int i =2;i<=50;i++) { sum+=flag*i; flag=-flag; } System.out.println(sum);法二:
int sum=1; for(int i=2;i<=50;i++) { if(i%2==0) { sum+=i; } else { sum-=i; } } System.out.printf("%-4d",sum); 27法一:
int sum=0,count=0; for(int i=1;i<=50;i++) { if(count!=3) { sum+=i; } else { sum-=i; count=0; } count++; } System.out.printf("%-4d",sum);法二:
int count=0; int sum=1; for(int i=2;i<=50;i++) { count++; if(count%3==1||count%3==2) sum=sum+i; else sum=sum-i; } System.out.println(sum); 427小题五:
本节课主要讲解的包这个东西
package sun; public class student { private int sage; public String sno; protected int grade; int height; Integer m ; public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("esfser"); } } package sun; public class text { public static void main(String[] args) { // TODO Auto-generated method stub student A=new student(); A.sno="123"; A.grade=123; A.height=123; student [] B=new student [10]; System.out.println(A.height); Integer m = new Integer(16); System.out.println(m); } }