2015年10月19日 星期一

進階練習一

Debug the following code segments. Remove all syntax and logical errors.

/***********************************************************/

1. The following code should print the word Tom ten times)

x=0;
while(x<10)
    System.out.println("Tom");
    x++;

/***********************************************************/

2. The following code should read an integer x inputted by user and print it.

Scanner input = new Scanner();
int x = input.nextLine();
System.out.println(x);


/***********************************************************/

3. The following code should assign the value of x to be the square root of y.

int x = sqrt(y);



/***********************************************************/


4. The following code should print all even integers from 50 to 100

for( i=2 ; i<=100; i+=2)
    System.out.println(i+50);


/***********************************************************/

沒有留言:

張貼留言