Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE ANSWER ALL PARTS IN JAVA PART 1 PART 2 Assume we have already defined a variable of type int called num with the following

PLEASE ANSWER ALL PARTS IN JAVA

PART 1

image text in transcribed

PART 2

image text in transcribed

Assume we have already defined a variable of type int called num with the following line of code: int num = ???; // 'num' can have any int value TASK: Print a centered triangle with num asterisks (*) on the bottom row, num - 2 asterisks on the next bottom row, ., and 1 asterisk on the top row, where the triangle is surrounded by hyphens (). You can assume that num is odd and is at least 3. EXAMPLE: If num is 5, the resulting triangle would be the following: --*-- - ***** Sample Input: Sample Output: --*-- -***- ***** Assume we have already defined a variable of type int called num with the following line of code: int num = ???; // 'num' can have any int value TASK: Print the prime numbers that are less than or equal to num (one per line). You may assume that num is greater than 1. HINT: Recall that a number is considered "prime" if it is only divisible by 1 and itself. HINT: 1 is not a prime number. HINT: You can use Math.sgrt(x) to take the square root of a variable x. No need to import anything: we've done that for you behind-the-scenes. Sample Input: 10 Sample Output

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

Oracle 12c SQL

Authors: Joan Casteel

3rd edition

1305251032, 978-1305251038

More Books

Students also viewed these Databases questions

Question

3. Who would the members be?

Answered: 1 week ago