In: Computer Science
What is printed?
public static void main(String[] args)
{
int i = 6;
aMeth(i);
System.out.print(i);
}
public static void aMeth(int i)
{
System.out.print(i);
i = i + 1;
System.out.print(i);
}
2)
What is printed as the value of b?
Scanner kybd = new Scanner(System.in);
System.out.println("Enter two ints " );
int i = kybd.nextInt();
int j = kybd.nextInt();
boolean b = ((i % 2) == 0) && ((j % 2) == 0);
System.out.println(b);
3)
Ans=>
1) What is printed?
The output will be 6 7 6
As first variable int i is initialize to value 6 => int i = 6.
Then it is passed to function Meth(int i)where it is first printed as 6.
Then in function meth i is incremented by 1 and again got printed as 7.
=>i = i + 1;
After which control returns back to main function and again prints i value as 6.
Here value of i in the main function will be equal to 6 and not 7 because its scope was only limited to that particular function. Hence output will be 6 7 6.
2) What is printed as the value of b?
The value of b depends on the input I & j from the user.
The statement (i % 2) == 0) =>returns true if remainder is zero after dividing value i by 2.
The outputs for corresponding inputs are as follows:
I |
J |
output |
Even |
Even |
True |
Even |
Odd |
False |
Odd |
Even |
False |
Odd |
Odd |
False |
.
If you have any query please ask .Thankyou..