Deck 4: Loops and Files
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/48
العب
ملء الشاشة (f)
Deck 4: Loops and Files
1
In the following code,what values could be read into number to terminate the while loop? Scanner keyboard = new Scanner(System.in);
System.out.print("Enter a number: ");
Int number = keyboard.nextInt();
While (number < 100 && number > 500)
{
System.out.print("Enter another number: ");
Number = keyboard.nextInt();
}
A) Numbers less than 100 or greater than 500
B) Numbers in the range 100 - 499
C) Numbers in the range 100 - 500
D) The boolean condition can never be true
System.out.print("Enter a number: ");
Int number = keyboard.nextInt();
While (number < 100 && number > 500)
{
System.out.print("Enter another number: ");
Number = keyboard.nextInt();
}
A) Numbers less than 100 or greater than 500
B) Numbers in the range 100 - 499
C) Numbers in the range 100 - 500
D) The boolean condition can never be true
D
2
What will be the value of x after the following code is executed? int x = 10,y = 20;
While (y < 100)
{
X += y;
}
A) 90
B) 110
C) 210
D) This is an infinite loop
While (y < 100)
{
X += y;
}
A) 90
B) 110
C) 210
D) This is an infinite loop
D
3
A loop that repeats a specific number of times is known as a(n)
A) sentinel loop
B) conditional loop
C) counter-controlled loop
D) infinite loop
A) sentinel loop
B) conditional loop
C) counter-controlled loop
D) infinite loop
C
4
What will be the value of x after the following code is executed? int x = 10;
Do
{
X *= 20;
}
While (x > 5);
A) 10
B) 200
C) This is an infinite loop.
D) The loop will not be executed,the initial value of x > 5.
Do
{
X *= 20;
}
While (x > 5);
A) 10
B) 200
C) This is an infinite loop.
D) The loop will not be executed,the initial value of x > 5.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
5
What will be the values of x and y as a result of the following code? int x = 25,y = 8;
X += y++;
A) x = 25,y = 8
B) x = 33,y = 8
C) x = 33,y = 9
D) x = 34,y = 9
X += y++;
A) x = 25,y = 8
B) x = 33,y = 8
C) x = 33,y = 9
D) x = 34,y = 9
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
6
Before entering a loop to compute a running total,the program should first do this.
A) Read all the values into main memory
B) Set the accumulator where the total will be kept to an initial value,usually zero
C) Know exactly how many values there are to total
D) Set all variables to zero
A) Read all the values into main memory
B) Set the accumulator where the total will be kept to an initial value,usually zero
C) Know exactly how many values there are to total
D) Set all variables to zero
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
7
This type of loop is ideal in situations where the exact number of iterations is known.
A) while loop
B) do-while loop
C) for loop
D) if statement
A) while loop
B) do-while loop
C) for loop
D) if statement
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
8
Which of the following will open a file named MyFile.txt and allow you to append data to its existing contents?
A) FileWriter fwriter = new FileWriter("MyFile.txt",true);
PrintWriter outFile = new PrintWriter(fwriter);
B) FileWriter fwriter = new FileWriter("MyFile.txt");
PrintWriter outFile = new PrintWriter(fwriter);
C) PrintWriter outfile = new PrintWriter("MyFile.txt",true);
D) PrintWriter outfile = new PrintWriter(true,"MyFile.txt");
A) FileWriter fwriter = new FileWriter("MyFile.txt",true);
PrintWriter outFile = new PrintWriter(fwriter);
B) FileWriter fwriter = new FileWriter("MyFile.txt");
PrintWriter outFile = new PrintWriter(fwriter);
C) PrintWriter outfile = new PrintWriter("MyFile.txt",true);
D) PrintWriter outfile = new PrintWriter(true,"MyFile.txt");
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
9
If a loop does not contain within itself a way to terminate,it is called a(n)
A) while loop
B) do-while loop
C) for loop
D) infinite loop
A) while loop
B) do-while loop
C) for loop
D) infinite loop
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
10
What will be the value of x after the following code is executed? int x,y = 4,z = 6;
X = (y++)* (++z);
A) 24
B) 28
C) 30
D) 35
X = (y++)* (++z);
A) 24
B) 28
C) 30
D) 35
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
11
What will be the value of x after the following code is executed? int x = 10;
For (int y = 5;y < 20;y +=5)
X += y;
A) 40
B) 25
C) 30
D) Invalid for statement
For (int y = 5;y < 20;y +=5)
X += y;
A) 40
B) 25
C) 30
D) Invalid for statement
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
12
This is a value that signals when the end of a list of values has been reached.
A) Terminal value
B) Final value
C) End value
D) Sentinel
A) Terminal value
B) Final value
C) End value
D) Sentinel
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
13
Assume that inputFile references a Scanner object that was used to open a file.Which of the following while loops shows the correct way to read data from the file until the end of the file is reached?
A) while (inputFile != null)
{ … }
B) while (!inputFile.EOF)
{ … }
C) while (inputFile.hasNext())
{ … }
D) while (inputFile.nextLine == " ")
{ … }
A) while (inputFile != null)
{ … }
B) while (!inputFile.EOF)
{ … }
C) while (inputFile.hasNext())
{ … }
D) while (inputFile.nextLine == " ")
{ … }
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
14
How many times will the following for loop be executed? for (int count = 10;count < = 21;count++)
System.out.println("Java is great!!!");
A) 1
B) 10
C) 11
D) 0
System.out.println("Java is great!!!");
A) 1
B) 10
C) 11
D) 0
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
15
How many times will the following do-while loop be executed? int x = 11;
Do
{
X += 20;
} while (x > 100);
A) 0
B) 1
C) 4
D) 5
Do
{
X += 20;
} while (x > 100);
A) 0
B) 1
C) 4
D) 5
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
16
What will be the values of x and y as a result of the following code? int x = 12,y = 5;
X += y--;
A) x = 12,y = 5
B) x = 16,y = 4
C) x = 17,y = 5
D) x = 17,y = 4
X += y--;
A) x = 12,y = 5
B) x = 16,y = 4
C) x = 17,y = 5
D) x = 17,y = 4
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
17
Given the following statement,which statement will write "Calvin" to the file DiskFile.txt? PrintWriter diskOut = new PrintWriter("DiskFile.txt");
A) System.out.println(diskOut,"Calvin");
B) DiskFile.println("Calvin");
C) PrintWriter.println("Calvin");
D) diskOut.println("Calvin");
A) System.out.println(diskOut,"Calvin");
B) DiskFile.println("Calvin");
C) PrintWriter.println("Calvin");
D) diskOut.println("Calvin");
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
18
This type of loop will always be executed at least once.
A) pre-test loop
B) post-test loop
C) sentinel loop
D) for loop
A) pre-test loop
B) post-test loop
C) sentinel loop
D) for loop
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
19
What will be the value of x after the following code is executed? int x = 10;
While (x < 100)
{
X += 10;
}
A) 90
B) 100
C) 110
D) This is an infinite loop
While (x < 100)
{
X += 10;
}
A) 90
B) 100
C) 110
D) This is an infinite loop
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
20
When using the PrintWriter class,which of the following import statements would you write near the top of your program?
A) import javax.swing.*;
B) import java.io.*;
C) import PrintWriter;
D) import java.file.*;
A) import javax.swing.*;
B) import java.io.*;
C) import PrintWriter;
D) import java.file.*;
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
21
Which of the following will open a file named MyFile.txt and allow you to read data from it?
A) File file = new File("MyFile.txt");
B) Scanner inputFile = new Scanner("MyFile.txt");
C) File file = new File("MyFile.txt");
Scanner inputFile = new Scanner(file);
D) PrintWriter inputFile = new PrintWriter("MyFile.txt");
A) File file = new File("MyFile.txt");
B) Scanner inputFile = new Scanner("MyFile.txt");
C) File file = new File("MyFile.txt");
Scanner inputFile = new Scanner(file);
D) PrintWriter inputFile = new PrintWriter("MyFile.txt");
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
22
You can use this method to determine whether a file exists.
A) The Scanner class's exists method
B) The File class's exists method
C) The File class's canOpen method
D) The PrintWriter class's fileExists method
A) The Scanner class's exists method
B) The File class's exists method
C) The File class's canOpen method
D) The PrintWriter class's fileExists method
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
23
What will be the value of x after the following code is executed? int x = 10;
While (x < 100);
{
X += 10;
}
A) 90
B) 100
C) 110
D) This is an infinite loop
While (x < 100);
{
X += 10;
}
A) 90
B) 100
C) 110
D) This is an infinite loop
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
24
What will be printed after the following code is executed? for (int number = 5;number < = 15;number +=3)
System.out.print(number + ",");
A) 5,6,7,8,9,10,11,12,13,14,15,
B) 5,8,11,14,17,
C) 5,8,11,14,
D) This is an invalid for statement
System.out.print(number + ",");
A) 5,6,7,8,9,10,11,12,13,14,15,
B) 5,8,11,14,17,
C) 5,8,11,14,
D) This is an invalid for statement
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
25
Assuming that inputFile references a Scanner object that was used to open a file,which of the following statements will read an int from the file?
A) int number = inputFile.nextInt();
B) int number = inputFile.next();
C) int number = inputFile.readInt();
D) int number = inputFile.integer();
A) int number = inputFile.nextInt();
B) int number = inputFile.next();
C) int number = inputFile.readInt();
D) int number = inputFile.integer();
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
26
What will be the value of x after the following code is executed? int x = 10;
Do
{
X *= 20;
}
While (x < 5);
A) 10
B) 200
C) This is an infinite loop.
D) The loop will not be executed,the initial value of x > 5.
Do
{
X *= 20;
}
While (x < 5);
A) 10
B) 200
C) This is an infinite loop.
D) The loop will not be executed,the initial value of x > 5.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
27
This is an item that separates other items.
A) Controller
B) Partition
C) Doorway
D) Delimiter
A) Controller
B) Partition
C) Doorway
D) Delimiter
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
28
A for loop normally performs which of these steps?
A) initializes a control variable to a starting value
B) tests the control variable by comparing it to a maximum/minimum value and terminate when the variable reaches that value
C) updates the control variable during each iteration
D) all of the above
E) None of the above
A) initializes a control variable to a starting value
B) tests the control variable by comparing it to a maximum/minimum value and terminate when the variable reaches that value
C) updates the control variable during each iteration
D) all of the above
E) None of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
29
A sentinel value _________ and signals that there are no more values to be entered.
A) is a different data type than the values being processed
B) is a special value that cannot be mistaken as a member of the list
C) indicates the start of a list
D) guards the list
A) is a different data type than the values being processed
B) is a special value that cannot be mistaken as a member of the list
C) indicates the start of a list
D) guards the list
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
30
How many times will the following do-while loop be executed? int x = 11;
Do
{
X += 20;
}
While (x < = 100);
A) 1
B) 3
C) 4
D) 5
Do
{
X += 20;
}
While (x < = 100);
A) 1
B) 3
C) 4
D) 5
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
31
This type of loop is ideal in situations where you always want the loop to iterate at least once.
A) while loop
B) do-while loop
C) for loop
D) if statement
A) while loop
B) do-while loop
C) for loop
D) if statement
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
32
This is a sum of numbers that accumulates with each iteration of a loop.
A) Running total
B) Final total
C) Grand finale
D) Galloping total
A) Running total
B) Final total
C) Grand finale
D) Galloping total
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
33
A loop that executes as long as a particular condition exists is called a(n)
A) sentinel loop
B) conditional loop
C) count-controlled loop
D) infinite loop
A) sentinel loop
B) conditional loop
C) count-controlled loop
D) infinite loop
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
34
In all but rare cases,loops must contain within themselves
A) arithmetic statements
B) if statements
C) a way to terminate
D) nested loops
A) arithmetic statements
B) if statements
C) a way to terminate
D) nested loops
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
35
In the for loop,the control variable cannot be initialized to a constant value and tested against a constant value.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
36
What will be the value of x after the following code is executed? int x = 10,y = 20;
While (y < 100)
{
X += y;
Y += 20;
}
A) 90
B) 110
C) 130
D) 210
While (y < 100)
{
X += y;
Y += 20;
}
A) 90
B) 110
C) 130
D) 210
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
37
In the following code,what values could be read into number to terminate the while loop? Scanner keyboard = new Scanner(System.in);
System.out.print("Enter a number: ");
Int number = keyboard.nextInt();
While (number < 100 || number > 500)
{
System.out.print("Enter another number: ");
Number = keyboard.nextInt();
}
A) Numbers less than 100
B) Numbers greater than 500
C) Numbers in the range 100 - 499
D) Numbers in the range 100 - 500
System.out.print("Enter a number: ");
Int number = keyboard.nextInt();
While (number < 100 || number > 500)
{
System.out.print("Enter another number: ");
Number = keyboard.nextInt();
}
A) Numbers less than 100
B) Numbers greater than 500
C) Numbers in the range 100 - 499
D) Numbers in the range 100 - 500
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
38
What will be the value of x after the following code is executed? int x,y = 15,z = 3;
X = (y--)/ (++z);
A) 3
B) 4
C) 5
D) 6
X = (y--)/ (++z);
A) 3
B) 4
C) 5
D) 6
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
39
The do-while loop is a pre-test loop.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
40
Which of the following are pre-test loops?
A) while,for,do-while
B) while,do-while
C) while,for
D) for,do-while
A) while,for,do-while
B) while,do-while
C) while,for
D) for,do-while
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
41
A file must always be opened before using it and closed when the program is finished using it.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
42
When you open a file with the PrintWriter class,the class can potentially throw an IOException.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
43
In a for statement,the control variable can only be incremented.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
44
When the break statement is encountered in a loop,all the statements in the body of the loop that appear after it are ignored,and the loop prepares for the next iteration.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
45
When the continue statement is encountered in a loop,all the statements in the body of the loop that appear after it are ignored,and the loop prepares for the next iteration.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
46
The do-while loop must be terminated with a semicolon.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
47
You can use the PrintWriter class to open a file for writing and write data to it.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
48
When you pass the name of a fi le to the PrintWriter constructor,and the file already
exists,it will be erased and a new empty file with the same name will be created.
exists,it will be erased and a new empty file with the same name will be created.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck