Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello I am looking for help solving and compiling this code. Your help is great thank you. import java.util.Scanner; public class Lab2 { public static

Hello I am looking for help solving and compiling this code. Your help is great thank you. import java.util.Scanner; public class Lab2 { public static void main(String[] args) { // This creates a Scanner called "keyboard" and asks the user to input a // number. I've provided it for you. Scanner keyboard = new Scanner(System.in); System.out.print("Input an integer between zero and 20 "); int number = keyboard.nextInt(); /* * Task 1: determine if the number is actually between zero and twenty. If it's * not, tell the user and then exit the program. Remember, you can exit the * program using System.exit(0); */ /* * Task 2: If the program hasn't exited, tell the user whether the number is * even or odd. Remember, a number is even if the remainder when dividing by * two is zero, and odd otherwise. * * Challenge: if you're clever, you can do this in one line with printf and * a ternary expression. This isn't required to get full credit, though. */ /* * Task 3: Print out the number to the first, second, third, fourth, and * fifth power, neatly aligned, with commas. Loops will make this easier, * but they're not required. For example: * * power result * 1 4 * 2 16 * 3 64 * 4 256 * 5 1,024 * * Hint: any number between zero and 20 to any power between one and five * will take no more than seven digits (nine including the commas) * * Hint: you can use the Math.pow(base, exponent) to compute a number to a * power, but it returns a double. You can cast it to an int like this: * * int two_cubed = (int)Math.pow(2, 3); * * or keep it as a double like this: * * double two_cubed_d = Math.pow(2, 3); */ } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Learn To Program Databases With Visual Basic 6

Authors: John Smiley

1st Edition

1902745035, 978-1902745039

More Books

Students also viewed these Databases questions

Question

Identify several examples of ethical investing and SRI.

Answered: 1 week ago