Question

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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.util.Scanner;

public class Squares {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter a positive integer: ");
        int n = in.nextInt();
        for (int i = 0; i * i < n; i++) {
            System.out.println(i * i);
        }
    }
}

Enter a positive integer: 120 100

Add a comment
Know the answer?
Add Answer to:
Write a java program that asks the user to enter an integer. The program should then...
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 the number of integers that...

    Write a Java program that: • Asks the user to enter the number of integers that he need to enter; • Asked him to enter integer by integer; • Print The number of Odd numbers entered and the number of Even numbers entered. Important notes: 1. You should have to copy and paste the Java as your answer for this question. DON’T take screen shot for your Java Code. It must be editable. 2. Take a screen shot for your...

  • Java: Write a program that prompts the user to enter integers in the range 1 to...

    Java: Write a program that prompts the user to enter integers in the range 1 to 50 and counts the occurrences of each integer. The program should also prompt the user for the number of integers that will be entered. As an example, if the user enters 10 integers (10, 20, 10, 30, 40, 49, 20, 10, 25, 10), the program output would be: 10 occurs 4 times 20 occurs 2 times 25 occurs 1 time 30 occurs 1 time...

  • ***** JAVA ONLY ***** Write a program that asks the user to enter the name of...

    ***** JAVA ONLY ***** Write a program that asks the user to enter the name of a file, and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the file. Use Notepad to create a simple file that can be used to test the program. ***** JAVA ONLY *****

  • Write a program which asks the user to enter an integer. Use switch statement to write...

    Write a program which asks the user to enter an integer. Use switch statement to write out the numeric word (such as ONE) if the user's input is 1; (see the sample run output for the usr input 2 or 3); otherwise, write OUT OF RANGE. Below are few sample runs: If the user enters a 1, the program will print: ONE TWO THREE Or, if the user enters a 2, the program will print: TWO THREE Or, if the...

  • Write a short program in Java that asks the user for an integer. Then ask the...

    Write a short program in Java that asks the user for an integer. Then ask the user for a letter. Print out the letter followed by the integer.

  • Write a program that asks the user to enter a number ofseconds.• There are...

    Starting Out with C++ (9th Edition)  Chapter 4, Problem 7PCWrite a program that asks the user to enter a number of seconds.• There are 86400 seconds in a day. If the number of seconds entered by the user is greater than or equal to 86400, the program should display the number of days in that many seconds.• There are 3600 seconds in an hour. If the number of seconds entered by the user is less than 86400, but is greater...

  • HELP IN JAVA: WHILE LOOP: Write a program that asks the user to enter a number...

    HELP IN JAVA: WHILE LOOP: Write a program that asks the user to enter a number of seconds. This number should be less than or equal to 32767 because that is the largest number pep8 can handle. Your program should then output the number of hours, minutes, and seconds on the planet of Crypton, where there are 64 seconds in a minute and 32 minutes in an hour.

  • 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...

  • C++ Write a program that asks user for a positive integer side length. If they enter...

    C++ Write a program that asks user for a positive integer side length. If they enter an illegal value, they must be prompted to enter a good one until they do. It then displays, using asterisks, a filled diamond of the given side length. For example, if the side length is 4, the program should display:

  • 2. Write a C++ program that asks the user to enter a integer between 1 and...

    2. Write a C++ program that asks the user to enter a integer between 1 and 10. Continue to prompt the user while the value entered does not fall within the range. When the user is successful display a congratulatory message. Save file as OneToTen.

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