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 8675747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:01:16+00:00 2026-06-12T20:01:16+00:00

I am not experienced in Java at all and am using a text editor

  • 0

I am not experienced in Java at all and am using a text editor to write code so I can’t see what the problem is (I am running from command line)
I see the error and know what it is but I have no idea how to fix it

System.out.print(String.format("%7d", Math.pow(n,2).toString()));

I also tried without the .toString()
Basically if I print only n it works, but the power function gives me an error probably because of return types, but pow should return a double and the string format %7d is probably also double right?

  • 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-06-12T20:01:17+00:00Added an answer on June 12, 2026 at 8:01 pm

    You are using wrong format specifier.. %d is used for integer.

    Math.pow() returns primitive double on which you cannot invoke toString() method.

    Try using %7s which is for String, and convert your primitive double value to Wrapper type: –

    String.format("%7s", Double.valueOf(Math.pow(n,2)).toString())
    

    But, you don’t need to convert your argument to String, you can directly use double value with %f: –

    String.format("%.3f", Math.pow(n,2));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hei there, I'm not experienced at all in C++ as I need to start
I'm not very experienced with JavaScript, but this code was similar to what I
I'm a long time developer but not very experienced with DNS. Here's my problem:
I was just trying out some code, not a experienced coder. I implemented(at least
Using JNBridge is it possible to update a JTextField's Text Property from a .Net
I am using Eclipse 3.5 for several different Java/JSP projects. All of our project
I have limited Java Socket experience and all of it using TCP. I am
i'm using git to manage my project, but i'm not much experienced in this
Problem description After a while of running my java server application I am experiencing
I'm not an experienced java developer so any comment will be welcomed ... I've

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.