Sunday, September 25, 2005

home2-2

3. Let i=2;
Print i;
Print 2 * (i++);
Print i;

public class Untitled1 {
public static void main(String[] args)
{
int i=2;
System.out.println("i="+i);
int j=(i++)*2;
System.out.println("2 * (i++)="+j);
System.out.println("i="+i);
}}


執行結果 i=2
2 * (i++)= 4
i= 3

4. Let i=2;
Print i;
Print 2 * (++i);
Print i;

public class Untitled1 {
public static void main(String[] args)
{
int i=2;
System.out.println("i="+i);
int j=2*(++i);
System.out.println("2 * (i++)="+j);
System.out.println("i="+i);
}}


執行結果 i=2
2 * (i++) = 6
i = 3

5. Let m=7, n=2;
Print (double) m/n;
Print m/ (double)n;

public class Untitled1 {
public static void main(String[] args)
{
int m=7,n=2;
System.out.println("(double) m/n="+(double) m/n);
System.out.println("m/ (double)n="+m/ (double)n);
}}

執行結果
(double) m/n=3.5
m/ (double)n=3.5


0 Comments:

Post a Comment

<< Home