CSCI 1301 Midterm Practice Test

0.0(0)
studied byStudied by 1 person
GameKnowt Play
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/18

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

19 Terms

1
New cards

Write a program that will print a table of squares by using a loop.

Enter the value of n: 5
Number Squared
_________________________________
1 1
2 4
3 9
4 16
5 25

Declare the variables?

int maxNumber, number, squaredNumber

2
New cards

Which is the following are valid Java identifiers (Programmer defined names)

a.) hourly pay
b.) 8numbers
c.) twoDays
d.) class
c.) Smallest

twoDays
Smallest

3
New cards

int k=1
while(k<=5)
{
System.out.println("Java is fun!");
k+=1;
}
System.out.println(k);

How many times will "Java is fun!" be printed on the screen?

5 Times

4
New cards

int k=1
while(k<=5)
{
System.out.println("Java is fun!");
k+=1;
}
System.out.println(k);

What will the value of k be printed on the screen after the loop finished

6

5
New cards

Which of the following statements will print the message "The distance the car traveled is 120 miles." , Suppose that the value of the variable miles is 120.

a.) System.out.println("The distance the car traveled is " +miles + "miles.");

b.) System.out.println("The distance the car traveled is " +" miles " + "miles.");

c.) System.out.println("The distance the car traveled is " + miles "miles.");

d.) None of the above

a.

6
New cards

Given the following coding, what is the output?
int x=1, y;
y=x++;
System.out.println("y=" +y)

a.) y=1
b.) y=2
c.) y=0
d.) unknown

a.) y=1

7
New cards

Assume the variables a=20, b=20, and c=30. Which of the following conditions return true (Indicate all that apply)

a.) a!=b && c>3
b.) a>c || b<10
c.) !(a==10)
d.)a==b && c<=30

c.) !(a==10)
d.)a==b && c<=30

8
New cards

int a=1, b=0
while(a<=5)

{
b+=a;
a++;
}
System.out.println(b);


What is the output of the above Java code?
a.) 15
b.) 10
c.) 5
d.) 0
e.) None of the above

a.)15

9
New cards

What will be the value of x after the following code is expected?

int y=10;
double x;
x=y/100;

a.) 0
b.) 0.1
c.) 0.0
d.) None is Correct

a.) 0

10
New cards

If str1 and str2 are both Strings, which of the following expressions will correctly determine whether they are equal

(1) (str1 == str2)
(2) str1.equals(str2)
(3) (str.compareTo(str2)==0)

2 and 3

11
New cards

If chr is a character variable, which of the following if statements is written correctly?

a.) if(chr= "a")
b.) (chr== "a")
c.) (chr= 'a')
d.) (chr== 'a')

d.) (chr== 'a')

12
New cards

Given an int variable k that has already been declared , use a for loop to print a single line consisting of 100 asterisks. Use no variables other than k.

while(k<100)
{
k+=0;
k++;
}
System.out.println(k);

13
New cards

Declare a char variable named letter

char letter

14
New cards

Write a statement that decreases the variable shelfLife by 4 if the variable outsideTemperature is greater than 90

if(outsideTempature>90)
shelfLife=-4

15
New cards

Write a program that will print a table of squares by using a loop.

Enter the value of n: 5
Number Squared
_________________________________
1 1
2 4
3 9
4 16
5 25

Establish varibles?

int maxNumber, number, squaredNumber;

16
New cards

Write a program that will print a table of squares by using a loop.

Enter the value of n: 5
Number Squared
_________________________________
1 1
2 4
3 9
4 16
5 25

Ask the user to enter the number?

System.out.println("Enter Number")
maxNumber = kb.nextInt();
number = 1

17
New cards

Write a program that will print a table of squares by using a loop.

Enter the value of n: 5
Number Squared
_________________________________
1 1
2 4
3 9
4 16
5 25

Write a loop that will create table above?

System.out.println("Number \t\t Squared");
System.out.println("-----------------------");

While(number<=maxNumber)
{
squaredNumber=number*number;
System.out.println(number + " \t\t " + squaredNumber);
number++;
}

18
New cards

Complete the steps in the following Java program.

Declare a string variable named mood?

String mood;

19
New cards

Complete the steps in the following Java program.

Get an input from user and store it to the mood variable?

kb=new Scanner
mood = kb.nextLine();