Question

1.Given a positive integer number says n, write a java program to print the first n...

1.Given a positive integer number says n, write a java program to print the first n squared numbers recursively.

Sample run 1:

Enter the value of n: 5
-------------------------------------

First 5 square numbers are:
1 4 9 16 25

Sample run 2:

Enter the value of n: 10
-------------------------------------
First 10 square numbers are:
1 4 9 16 25 36 49 64 81 100

Sample run 3:

Enter the value of n: 12
-------------------------------------
First 12 square numbers are:
1 4 9 16 25 36 49 64 81 100 121 144

2.Consider the following interface:

interface Validate

{    boolean check(Object o); }

Classes that implement Validate interface, check against specific conditions to evaluate the object O. For example, a class validateAge checks if a birth year indicated by the person’s age is over 18 years old or not. If v is a validateAge object, then v.check(2001) returns true, and v.check(2003) returns false. Write the class validateAge, and recall casting from a type to another.

please have written answer

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Thanks for the question, Please post only 1 question at a time. As per Chegg policy, we are limited to answering only 1 question at a time.

Please post Question 2 and will help you out in that as well.

Here is the code for Question 1

===============================================================

import java.util.Scanner;



public class FirstNSquares {



    public static void main(String[] args) {



        Scanner scanner = new Scanner(System.in);

        System.out.print("Enter the value of n: ");

        int n = scanner.nextInt();



        System.out.printf("First %d square numbers are:\n",n);

        for(int number=1; number<=n;number++){

            System.out.print(number*number+" ");

        }

    }

}

===============================================================

Add a comment
Know the answer?
Add Answer to:
1.Given a positive integer number says n, write a java program to print the first n...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a java program that asks the user to enter an integer. The program should then...

    Write a java program that asks the user to enter an integer. The program should then print all squares less than the number entered by the user. For example, if the user enters 120, the program should display 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, and 100.

  • Please write in java Write a main program that runs the following two recursive methods demonstrating...

    Please write in java Write a main program that runs the following two recursive methods demonstrating that they work. #1) Write a recursive method writeSquares that accepts an integer n and prints the first n squares with the odd squares in decending order, followed by the even squares in acending order. For example • writeSquares(8): prints . 49 25 9 1 4 16 36 64 • writeSquares(11); prints 121 81 49 25 9 1 2 16 36 64 100 •...

  • write a program in java to print all the powers of 2 below a certain number...

    write a program in java to print all the powers of 2 below a certain number and calculate their sum. Make sure your program conforms to the following requirements. 1. Accept the upper limit from the user (as an integer). 2. These numbers grow very fast. make sure the sum variable is of the "long" type. You can assume that the test output will be less that LONG MAX. 3.Print all numbers as a running sum, and finally print their...

  • Write a C program to print the figure as follows. 5, Write a C program to...

    Write a C program to print the figure as follows. 5, Write a C program to print the figure as follows. 1 2 3 4 5 6 7 8 9 2 3 4 5 6 7 8 9 4 6 8 10 12 14 16 18 9 12 15 18 21 24 27 16 20 24 28 32 36 25 30 35 40 45 36 42 48 54 49 56 63 64 72 81 1 Tip: use loop.

  • Write a Python program to print a timetable. E.g. printTimesTable(n), 1<n<10 Or you can make your...

    Write a Python program to print a timetable. E.g. printTimesTable(n), 1<n<10 Or you can make your program be interactive with user by S. Asking user to input their number n. Your program will generate a table such as the following: 1 2 3456789 24 6 8 10 12 14 16 18 3 6 91215 18 21 24 27 4 812 16 20 24 28 32 36 5 10 15 20 25 30 35 40 45 6 12 18 24 30...

  • Python programming: Write a while loop that prints a. All squares less than n. For example,...

    Python programming: Write a while loop that prints a. All squares less than n. For example, if n is 100, print 0 1 4 9 16 25 36 49 64 81. b. All positive numbers that are divisible by 10 and less than n. For example, if n is 100, print 10 20 30 40 50 60 70 80 90 c. All powers of two less than n. For example, if n is 100, print 1 2 4 8 16...

  • Write a java program to print all the prime numbers below a certain given number. A...

    Write a java program to print all the prime numbers below a certain given number. A prime number is defined as a number that can only be divided by 1 and itself. Requirements: 1. Accept the upper limit from the user as an integer. 2. You can assume the user input will be positive and smaller than INT MAX 3. Go from 1 to the number. If you happen to find a number that is prime, print it. The input...

  • Java Magic Square: A n x n matrix that is filled with the numbers 1, 2,...

    Java Magic Square: A n x n matrix that is filled with the numbers 1, 2, 3,.... n^2 is a magic square if the sum of the elements in each row, in each column, and in the two diagonals is the same value. I need to write an application that gets 16 values as user input, in any order. Store these values in an ArrayList. When the numbers are put into a square, this would be a 4x4 two-dimensional array....

  • JAVA: (15 marks) Write a program that creates an integer array with 50 random values, prompts...

    JAVA: (15 marks) Write a program that creates an integer array with 50 random values, prompts the user to enter the index of an element in the array between 0 and 49, then displays the corresponding element value. If the specified index is out of bounds, display an error message (e.g. "Out of Bounds") and ask the user to enter another index. Use a while loop that will keep prompting the user until a valid input is received. To handle...

  • Write a Java program to convert octal (integer) numbers into their decimal number equivalents (exactly the...

    Write a Java program to convert octal (integer) numbers into their decimal number equivalents (exactly the opposite of what you have done in Assignment 4). Make sure that you create a new Project and Java class file for this assignment. Your file should be named “Main.java”. You can read about octal-to-decimal number conversions on wikepedia Assignment 4 is at the bottom Objective Your program should prompt the user to enter a number of no greater than 8 digits. If the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT