1/18
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
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
Which is the following are valid Java identifiers (Programmer defined names)
a.) hourly pay
b.) 8numbers
c.) twoDays
d.) class
c.) Smallest
twoDays
Smallest
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
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
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.
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
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
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
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
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
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')
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);
Declare a char variable named letter
char letter
Write a statement that decreases the variable shelfLife by 4 if the variable outsideTemperature is greater than 90
if(outsideTempature>90)
shelfLife=-4
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;
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
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++;
}
Complete the steps in the following Java program.
Declare a string variable named mood?
String mood;
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();