1.
int a=10;
System.out.print(a++);
int b=a++;
System.out.println(++a);
System.out.println(b--);
System.out.println(-(--b));
--------------------------------------------------------------------
2.
int a = 5;
int b = a%=2;
System.out.println(-(b*=++b));
int c = a/=0; // be carefully
System.out.println(c);
--------------------------------------------------------------------
Print the pattern:
3.1
int n=5;
for(int i=0; i<n ; i++){
System.out.println("*");
}
3.2
int n=5;
for(int i=0; i<n; i++){
System.out.print("x");
}
--------------------------------------------------------------------
4.
for( int i=0; i<3 ; i++){
System.out.print("* ");
System.out.print("* ");
}
System.out.println();
for( int i=0; i<3 ; i++)
System.out.print("* ");
System.out.print("* ");
--------------------------------------------------------------------
5. Ans how many star will be created in following questions:
5.1)
for(int i=0; i<5 ; i++)
System.out.print("*");
5.2)
for(int i=0; i<=5 ; i++) {
System.out.print("*");
}
5.3)
for(int i=1; i<5 ; i++)
System.out.print("*");
System.out.print("*");
5.4)
for(int i=1; i<=10 ; i++)
System.out.print("*");
5.5)
for(int i=0; i<10 ; i++);
System.out.print("*");
System.out.print("*");
5.6)
for(int i=0; i<5; i++){
System.out.print("*");
}
for(int i=0; i<=4; i++){
System.out.print("*");
}
5.7)
for(int i=0; i<3 ; i++){
for(int j=0; j<10; j++){
System.out.println("*");
}
}
5.8)
for(int i=0; i<3 ; i++){
for(int j=0; j<10; j++){
System.out.print("*");
}
System.out.println("*");
}
5.9)
for(int i=0; i<3 ; i++){
for(int j=0; j<10; j++){
System.out.print("*");
}
System.out.println(j);
}
--------------------------------------------------------------------
6. Think and draw what patterns will be displayed in each programs.
6.1)
for (int i=0; i<5; i++){
for(int j=0; j<=i ;j++){
System.out.print("*");
}
System.out.print("\n");
}
6.2)
int n = 5;
for (int i=1; i<=n; i++){
for(int j=1; j<=n-i ; j++){
System.out.print("_ ");
}
for(int j=1; j<=i; j++){
System.out.print("* ");
}
System.out.print("\n");
}
沒有留言:
張貼留言