
Java jumbled code, strings, methods

Quiz
•
Computers
•
10th Grade
•
Medium
Roopa Pulapaka
Used 1+ times
FREE Resource
19 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
2 mins • 1 pt
Find the correct code to find the reverse of a number. For example if the number is 234, the output should be 432
while (n > 0) {
n = n / 10;
rem = n % 10;
rev = (rev * 10) + rem;
}
while (n > 0) {
rem = n % 10;
rev = (rev * 10) + rem;
n = n / 10;
}
while (n > 0) {
rem = n % 10;
rev = (rem * 10) + rev;
n = n / 10;
}
while (n < 0) {
rem = n % 10;
rev = (rev * 10) + rem;
n = n / 10;
}
2.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
Identify the code that gives the sum of the digits of a number? If the number is 567 the sum is 18
while (number > 0) {
number = number % 10;
sum = sum + remainder;
number = number / 10;
}
System.out.print(sum)
while (number > 0) {
remainder = number / 10;
sum = sum + remainder;
number = number % 10;
}
System.out.print(sum)
while (number > 0) {
remainder = number % 10;
sum = sum + number;
number = number / 10;
}
System.out.print(sum)
while (number > 0) {
remainder = number % 10;
sum = sum + remainder;
number = number / 10;
}
System.out.print(sum)
3.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
Identify the correct code to check if a number is prime or not. num is the number to check.
boolean flag = false
for (int i = 1; i <= num / 2; ++i)
{
if (num % i == 0) {
flag = true; break;
}
}
if (!flag) System.out.println("prime"); else
System.out.println(" not prime");
boolean flag = false
for (int i = 2; i <= num / 2; ++i)
{
if (num % i == 0) {
flag = true; break;
}
}
if (!flag) System.out.println("prime"); else
System.out.println(" not prime");
boolean flag = false
for (int i = 2; i <= num / 2; ++i)
{
if (num % i == 0) {
flag = true; break;
}
}
if (flag) System.out.println("prime"); else
System.out.println(" not prime");
boolean flag = true
for (int i = 2; i <= num / 2; ++i)
{
if (num % i != 0) {
flag = true; break;
}
}
if (!flag) System.out.println("prime"); else
System.out.println(" not prime");
4.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
identify the correct java code snippet to check if a String is a palindrome. Variable len is the length of the String.
boolean isPalin = true;
for (int i = 0; i < len / 2; i++) {
if (str.charAt(i) != str.charAt(len- 1 - i)) {
isPalin = false;
break;
} }
if (isPalin)
System.out.println("palindrome");
else
System.out.println("not palindrome.")
boolean isPalin = true;
for (int i = 0; i < len / 2; i++) {
if (str.charAt(i) != str.charAt(len- 1 - i)) {
isPalin = false;
break;
} }
if (!isPalin)
System.out.println("palindrome");
else
System.out.println("not palindrome.")
boolean isPalin = true;
for (int i = 0; i < len / 2; i++) {
if (str.charAt(i) == str.charAt(len- 1 - i)) {
isPalin = false;
break;
} }
if (isPalin)
System.out.println("palindrome");
else
System.out.println("not palindrome.")
5.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
what is the min and max value of short data type in Java?
-216 and 216-1
-215 and 215-1
-231 and 231-1
215 and -215-1
6.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
what is the default value of a boolean data type?
true
false
7.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
A variable declared within the opening and closing parenthesis of a method signature is called a ____.
local
parameter
instance
class
Create a free account and access millions of resources
Similar Resources on Wayground
18 questions
FOR and WHILE loop in Python

Quiz
•
9th - 12th Grade
19 questions
CS2 Arrays Review

Quiz
•
9th - 12th Grade
20 questions
X - Progdas - Array dan Fungsi

Quiz
•
10th Grade
15 questions
Python Casting and Input

Quiz
•
8th - 11th Grade
15 questions
Java Math

Quiz
•
9th - 12th Grade
20 questions
كائنات بلغة جافا الفئة كتاب

Quiz
•
10th Grade - University
22 questions
AP CSA Unit 8 Review: 2D Arrays

Quiz
•
9th - 12th Grade
15 questions
Unit 8 - Searching and Sorting

Quiz
•
9th - 12th Grade
Popular Resources on Wayground
10 questions
Video Games

Quiz
•
6th - 12th Grade
20 questions
Brand Labels

Quiz
•
5th - 12th Grade
15 questions
Core 4 of Customer Service - Student Edition

Quiz
•
6th - 8th Grade
15 questions
What is Bullying?- Bullying Lesson Series 6-12

Lesson
•
11th Grade
25 questions
Multiplication Facts

Quiz
•
5th Grade
15 questions
Subtracting Integers

Quiz
•
7th Grade
22 questions
Adding Integers

Quiz
•
6th Grade
10 questions
Exploring Digital Citizenship Essentials

Interactive video
•
6th - 10th Grade
Discover more resources for Computers
10 questions
Exploring Digital Citizenship Essentials

Interactive video
•
6th - 10th Grade
10 questions
Proper Keyboarding Techniques

Interactive video
•
6th - 10th Grade
10 questions
Understanding Computers: Hardware, Software, and Operating Systems

Interactive video
•
7th - 12th Grade
29 questions
AP CSP Unit 2 Review (Code.org)

Quiz
•
10th - 12th Grade