Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6685029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:00:35+00:00 2026-05-26T05:00:35+00:00

import javax.swing.JOptionPane; public class PredefinedClass { public static void main(String[] args){ do{ String input

  • 0
    import javax.swing.JOptionPane;

public class PredefinedClass {
    public static void main(String[] args){
        do{
            String input = JOptionPane.showInputDialog("Enter a character:");
            if(input.length() > 1){
                JOptionPane.showMessageDialog(null,"Invalid Input. Input a character only.");
            }else if(Character.isLetter(input.charAt(0))){
                if(Character.isUpperCase(input.charAt(0))){
                    JOptionPane.showMessageDialog(null,"The character is an Uppercase letter.");
                }else if(Character.isLowerCase(input.charAt(0))){
                    JOptionPane.showMessageDialog(null,"The character is a Lowercase letter.");
                }
            }else if(Character.isDigit(input.charAt(0))){
                JOptionPane.showMessageDialog(null,"The character is a digit."+
                                                   "\nThe square root of "+input+" is "+Math.sqrt(input.charAt(0)));

            }
        }while(JOptionPane.showConfirmDialog(null,"Try again?[Y/N]","Try again?[Y/N]",JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION);
    }
}

Math.sqrt(input.charAt(0)) when i try 9 it’s outputting 7.54 which should be 3. Why is it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T05:00:36+00:00Added an answer on May 26, 2026 at 5:00 am

    input.charAt() returns the character, not the numeric value of the digit. This means you’re getting '9', as opposed to 9. The ASCII value of '9' is 57, so you end up taking the square root of that.

    Try Math.sqrt(input.charAt(0) - '0') instead.

    If you want to make your code a little bit more generic, consider using Integer.valueOf() or Double.valueOf() instead of looking at the individual characters.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

import java.util.scanner; import javax.swing.JOptionPane; public class FirstHomeJavaApplet{ public static void main(String[] args){ int num1=2;
import javax.swing.JOptionPane; import java.text.DecimalFormat; public class CandleLine { public static void main(String[] args) {
import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; public class tictac2 implements ActionListener{ static
import java.io.FileNotFoundException; import java.lang.SecurityException; import java.util.Formatter; import java.util.FormatterClosedException; import java.util.NoSuchElementException; import javax.swing.JOptionPane; public class
import java.io.FileNotFoundException; import java.lang.SecurityException; import java.util.Formatter; import java.util.FormatterClosedException; import java.util.NoSuchElementException; import javax.swing.JOptionPane; public class
import javax.swing.JOptionPane; public class Mate { double suma (double x1,double x2) {return x1+x2;} double
package jtextareatest; import java.io.FileInputStream; import java.io.IOException; import javax.swing.*; public class Jtextareatest { public static
import java.awt.Component; import java.awt.Dimension; import java.awt.Toolkit; import javax.swing.JOptionPane; public class NewJFrame extends javax.swing.JFrame {
import javax.swing.JFrame; import javax.swing.JPanel; import java.awt.Frame; import java.awt.Graphics; import java.awt.Color; import java.util.Random; public class
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class File { private JFrame frame1; private

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.