Hello: Names Red, wanting to get java tips aka teaching an old dog new tricks. Hobbies are carbon bikes, biodiesel, remodeling the moneypit. Grandkids are the prio though, breaking in my 5 year old grandson to be my wingman when I hit the trails on the bike, the granddaughter will get the pull behind rickshaw ride and be my spring weight training regimen. Well thanks for entertaining any newbie questions.

9 Years
Discussion Span
Last Post by Red Ruffansore

Thanks much, when I posted last night I was very tired and painted into a corner. I got my program to compile with output today and now my only issue is look of the output. IF you have any pointers on how to control println or how to tweak printf with the math.sqrt invovled, that would be great. Heres what I have that works and I commented out my failed attempt at printf.

public class SqrtPgm {

     * @param args
    public static void main(String[] args) {

        int MAX_NUMBER = 20;
        // Display table headings
        System.out.println("Number SquareRoot");

        /** Do some math, see if even then 
         *  return the square root of a given integer
         *  until maxxed out */

        for (int i = 0; i <=MAX_NUMBER; i += 2)
        System.out.println( i + "    "+ Math.sqrt(i));
        //System.out.printf("%-8d + Math.sqrt%-7d\n(i");



Thanks for the support, I think this site is going to be a real help in learning this language.

Edited by mike_2000_17: Fixed formatting


apparently the post compresses some spaces, I had the println with more spaces in between the quotes to force the second field to justify better. It should create output starting with 0 flush left under Number and follow with the sqrt under Square Root but with a jagged output with too much output to the right of the decimal place.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.