Social Sciences, asked by iiftva, 2 months ago

system.out.println ( Number="+2+7)
system.out.println(" Number= "+ (2+7)​

Answers

Answered by snighdashreya42
0

Explanation:

Change the following program to use compound assignments:

class ArithmeticDemo {

public static void main (String[] args){

int result = 1 + 2; // result is now 3

System.out.println(result);

result = result - 1; // result is now 2

System.out.println(result);

result = result * 2; // result is now 4

System.out.println(result);

result = result / 2; // result is now 2

System.out.println(result);

result = result + 8; // result is now 10

result = result % 7; // result is now 3

System.out.println(result);

}

}

Here is one solution:

class ArithmeticDemo {

public static void main (String[] args){

int result = 3;

System.out.println(result);

result -= 1; // result is now 2

System.out.println(result);

result *= 2; // result is now 4

System.out.println(result);

result /= 2; // result is now 2

System.out.println(result);

result += 8; // result is now 10

result %= 7; // result is now 3

System.out.println(result);

}

}

In the following program, explain why the value "6" is printed twice in a row:

class PrePostDemo {

public static void main(String[] args){

int i = 3;

i++;

System.out.println(i); // "4"

++i;

System.out.println(i); // "5"

System.out.println(++i); // "6"

System.out.println(i++); // "6"

System.out.println(i); // "7"

}

}

Similar questions