Question

Class name: "NextSquare" Prompt the user to enter an integer. display your name and the next...

Class name: "NextSquare"

Prompt the user to enter an integer.

display your name and the next integer larger than the input integer which is a perfect square.

for example, if the input is 7, the output should be (your name plus) 9.

I am looking for help with this and need the answer to be in JOptionPane with java language.

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

// Screenshot of the code & output


// Sample output

// code to copy

NextSquare.java

import javax.swing.JOptionPane;

public class NextSquare {

   public static void main(String[] args) {
       int num = Integer.parseInt(JOptionPane.showInputDialog("Enter a number :"));
       int nextNum=nextPerfectSquare(num);
       JOptionPane.showMessageDialog(null, "Srinivas " + nextNum, " ", JOptionPane.PLAIN_MESSAGE);

   }

   private static int nextPerfectSquare(int num) {
       int nextN = (int)Math.floor(Math.sqrt(num)) + 1;       
   return nextN * nextN;
      
   }

}

Add a comment
Know the answer?
Add Answer to:
Class name: "NextSquare" Prompt the user to enter an integer. display your name and the next...
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
  • in java Write an application called Squaring that will: • Prompt the user to enter an...

    in java Write an application called Squaring that will: • Prompt the user to enter an integer greater than 1. Your code for this should be type-safe and validate the number, meaning that your code should re-prompt the user for another entry if they enter anything other than an integer that is greater than 1. • Repeatedly square the integer until it exceeds 1 million, outputting the value each time after squaring. • Output the number of squarings required to...

  • Write a program in Java language to prompt the user to enter 3 integers (A, B,...

    Write a program in Java language to prompt the user to enter 3 integers (A, B, and C) then display these numbers from the lowest to the highest (sorted ascendingly) . Note that there are 6 different cases to handle proper order. As an example, a user entered 10 for A, 5 for B and 14 for C: the output of the program should look like this Enter number A? 10 Enter number B? 5 Enter number C? 14 Your...

  • Summary: Write a C program that prompts the user to enter 2 positive integer numbers, display...

    Summary: Write a C program that prompts the user to enter 2 positive integer numbers, display the numbers in 3 formats. Then check, whether the larger of the 2 is evenly divisible by the smaller. Detail: Write a complete C program, more complex than the typical "hello world" program. Prompt the user to enter 2 integer numbers that are not negative. After either entry, display that number again. Print the smaller in hexadecimal, in decimal, and in octal format. Include...

  • MATLAB script 1) Prompt the user for their first name 2) Prompt the user for their...

    MATLAB script 1) Prompt the user for their first name 2) Prompt the user for their last name 3) Prompt the user for their age Display a sentence that greets the user using their first and last name, and congratulates them for what will be their age on their next birthday. Example: Hello John Smith. Congratulations on turning 45 on your next birthday!

  • 1. Write a program that prompts the user to enter three integers and display the integers...

    1. Write a program that prompts the user to enter three integers and display the integers in non-decreasing order. You can assume that all numbers are valid. For example: Input Result 140 -5 10 Enter a number: Enter a number: Enter a number: -5, 10, 140 import java.util.Scanner; public class Lab01 { public static void main(String[] args) { Scanner input = new Scanner(System.in);    } } ---------------------------------------------------------------------------------------------------------------------------- 2. Write a program that repeatedly prompts the user for integer values from...

  • 1. Prompt the user for one of the arithmetic operators ('op'): +, -, *,/, or **...

    1. Prompt the user for one of the arithmetic operators ('op'): +, -, *,/, or ** 2. Prompt the user for two input integers ('a' and'b') 3. The input numbers can be positive or negative 4. Perform the arithmetic operation using the two input numbers 5. The first entered number ('a') is the left side, the second ('b') the right side of the operation For exponentiation, the first number is the base, the second the exponent Print (display) the following...

  • C++ Program Help Prompt your user to enter a length of a word to search from...

    C++ Program Help Prompt your user to enter a length of a word to search from a string. Use forking to spawn a child process to perform the counting task. Allow the child process to finish and output the number of words found (if any), before prompting the user for the next length. Count all words in the string with this length and output the number of words that correspond to this length. Program keeps asking user for length till...

  • Y F G Prompt and Store. 5. Prompt the user with "Enter your weight in pounds:...

    Y F G Prompt and Store. 5. Prompt the user with "Enter your weight in pounds: "message and store in the weight variable. 6. Initialize an int variable named heightIn Inches to feet OſHeight times 12 plus Inches OfHeight. 7. Initialize a double variable named BMI to weight * 703.0 heightIrinches El VB 8. Initialize a double variable named ratio to height In Inches? 703.0 9. Initialize a double variable named lower Normal to 18.5 times ratio. 10. Initialize a...

  • If the user types: 67<ENTER> in response to the prompt, what does print display? answer =...

    If the user types: 67<ENTER> in response to the prompt, what does print display? answer = 67 if input("Please enter a guess ") == 67: print("Your guess is correct") else: print("Your guess is not correct") Select one: Your guess is not correct An error message Your guess is correct

  • JAVA Ask the user for integers. If the user did not enter an integer, ask again....

    JAVA Ask the user for integers. If the user did not enter an integer, ask again. (Type Safe Input) Keep a running total of the intergers entered (sum). Once the user enters 0, stop looping. Print the sum of all the numbers. Do not use try-catch. EXAMPLE OUTPUT: Enter an integer, 0 to stop> [fasdfsa] Invalid input. Enter an integer, 0 to stop> [231.342] Invalid input. Enter an integer, 0 to stop> [1] Enter an integer, 0 to stop> [2]...

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