QUESTION 17 Complete the code, changing the color of the Graphics reference g to
ID: 666083 • Letter: Q
Question
QUESTION 17
Complete the code, changing the color of the Graphics reference g to a color with red=100, green=200, blue=60
public void paint( Graphics g )
{
// your code goes here
}
QUESTION 18
Complete the code, drawing a line between points (100, 200) and (34, 67)
public void paint( Graphics g )
{
// your code goes here
}
QUESTION 19
The 4 relational operators, >, >=, <, <= are binary operators.
True
False
QUESTION 20
!( a > 3 ) is equivalent to _________________ .
a < 3
a <= 3
!a < 3
!a <= 3
!( a <= 3 )
QUESTION 21
What is the output of the following code? _________________ .
int age = 30;
if ( age > 33 )
System.out.print( 1 );
else
System.out.print( 2 );
System.out.println( 3 );
1
2
12
123
23
QUESTION 22
When we use a while loop, we always know in advance how many times the loop body will be executed.
True
False
QUESTION 23
When reading data from a file using a while loop, the typical condition to exit the loop is when ___________.
We have read the first value in the file
We have read 100 values in the file
We have reached the end of the file
QUESTION 24
Write a loop to output the word EXAM 99 times
QUESTION 25
Write a loop to calculate the total of all the numbers between 100 and 200 included (i.e. 100 + 101 + … + 199 + 200); output the total.
a < 3
a <= 3
!a < 3
!a <= 3
!( a <= 3 )
QUESTION 21
What is the output of the following code? _________________ .
int age = 30;
if ( age > 33 )
System.out.print( 1 );
else
System.out.print( 2 );
System.out.println( 3 );
1
2
12
123
23
QUESTION 22
When we use a while loop, we always know in advance how many times the loop body will be executed.
True
False
QUESTION 23
When reading data from a file using a while loop, the typical condition to exit the loop is when ___________.
We have read the first value in the file
We have read 100 values in the file
We have reached the end of the file
QUESTION 24
Write a loop to output the word EXAM 99 times
QUESTION 25
Write a loop to calculate the total of all the numbers between 100 and 200 included (i.e. 100 + 101 + … + 199 + 200); output the total.
Explanation / Answer
Answers:
Question 17:
public void paint( Graphics g )
{
private int width=100;
private int height=50;
System.out.println("Program to change the color ");
int red_value=100;
int green_value=200;
int blue_value=60;
System.out.println("Value of red color is"+red_value);
System.out.println("Value of green color is"+green_value);
System.out.println("Value of blue color is"+blue_value);
}
Question 18:
public void paint( Graphics g )
{
System.out.println("The values of cordinates are" "("+start_x-coordinate","+start_y-coordinate")" "and" "("+end_x-coordinate","+end_y-coordinate")" ;
}
Question 19:
The answer is true.Binary operators are operator that operates on two operands and manipulates them to return a results.
Syntax:operand1 operator operand2
Example:x1>x2
x1<x2
x1<=x2
x1>=x2
Question 20:
! Called Logical NOT Operator is used to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false.
Hence the Answer to this question is :a < 3
Question 21:
It has a conditional 'if-else" statement.It checks "if" the condition is satisfied i.e(age>33) in this case its not true since age =30(declared),therefore statement following if statement will be ignored.
The statements following "else" statement will be executed.
Hence the Answer to this question is :23
Question 22:
A while loop is a control structure that allows you to repeat a certain task a certain number of times.
Syntax:
The prototype of a while loop is:
A while loop executes an unknown number of times, as long at the BOOLEAN EXPRESSION is true.Therefore it doesn't know how many times its going to execute.If the condition is never true at all then th loop goes into infinte loop
Hence the Answer is:False
Question 23:When reading the contents of the file the file read stops when the file pointer reaches the end of the file
Hence the answer is:When we have reached the end of the file.
Question 24:
Answer:
while(value<=99){
System.out.println("EXAM");
}
while the contents of value <=99 the statement EXAM will be executed.i.e 99 times the statement EXAM will be executed.
Question 25:
Answer to this question is:
public class SumArrayForLoop{
public static void manin(String[] args){
int [] numbers =new int[]{100..200};
int sum=0;
for(int i=0;i<numbers.length;i++){
sum=sum+numbers[i];}
System.out.println("sum of array numbers is:"+sum);
}
We declare an array of elements from 100 to 200 and the use a for loop to iterate over the loop till the end of the array.Therefore the above for loop iterates from 100,101,102....199,200 and sum =sum(initially 0) +number[value from loop] and finally we use print statement to print this sum.
Hope that helps...HAPPY ANSWERING!!!!!!!!!!!!!!!!!!!!!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.