How to Square a Number in Java


Choose an answer and hit 'next'. You will receive your score and answers at the end.

question 1 of 3

The following code will not compile. What needs to be added or removed so it will compile successfully?

Create Your Account To Take This Quiz

As a member, you'll also get unlimited access to over 79,000 lessons in math, English, science, history, and more. Plus, get practice tests, quizzes, and personalized coaching to help you succeed.

Try it risk-free
Try it risk-free for 30 days. Cancel anytime
Already registered? Log in here for access

1. Which of the following correctly generates the square of the number 7?

2. Based on the variables below, which is the correct way to square 19?

Create your account to access this entire worksheet
A Premium account gives you access to all lesson, practice exams, quizzes & worksheets
Access to all video lessons
Quizzes, practice exams & worksheets
Certificate of Completion
Access to instructors
Create an account to get started Create Account

About This Quiz and Worksheet

Inside this quiz and worksheet combination, you are tested on your understanding of squaring numbers in Java. Questions focus on something that should be added or removed to get a piece of code to compile, as well as the value of a variable within a given piece of code.

Quiz and Worksheet Goals

Your knowledge of the topics listed below will be tested in this quiz:

  • Generating a square from a selection of codes
  • Why a piece of code will not compile
  • What is missing from a given piece of code
  • The value of a specific variable in a code segment

Skills Practiced

  • Making connections - use what you've learned about Java to understand why a given piece of code will not compile
  • Information recall - remember what you have learned about variables in the Java language
  • Knowledge application - use what you know to answer questions about missing pieces of code

Additional Learning

To discover more, check out the lesson titled How to Square a Number in Java. With this lesson, you can dive into the extra topics listed below:

  • Viewing the output of a squared number
  • Using Math.pow()
  • Utilizing the correct variable