Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 12 of 12

Thread: Printing from a Method

  1. #1
    Member
    Join Date
    Sep 2012
    Posts
    98
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Printing from a Method

    My last post was kind of buggy, so heres this one. My code will not print method printTrigTables, but it prints the other two declared in main
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package mathtables;
     
    /**
     *
     * @author student
     */
    public class MathTables {
     
     
        public static void main(String[] args) {
            double a1;
            double a2;
            double a3;
            double a4;
            double a5;
            double a6;
            double a7;
            double a8;
            double a9;
            double a10;
            double a11;
            double a12;
            a1 = 1;
            a2 = 1;
            a3 = 1;
            a4 = 1;
            a5 = 1;
            a6 = 1;
            a7 = 1;
            a8 = 1;
            a9 = 1;
            a10 = 1;
            a11 = 1;
            a12 = 1;
     
            printCommonLogTable();
            printAdditionTable ();
            printTrigTables(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12);
     
        }
     
        public static void printCommonLogTable () {
            double x = .5;
            while (x < 10.0) {
                System.out.println(x + "  " + Math.log(x));
                x = x + .5;
            }
     
     
        }
        public static void printAdditionTable () {
     
            System.out.println("+ 0 1 2 3 4 5 6 7 8 9");
            System.out.println("0 0 1 2 3 4 5 6 7 8 9");
            System.out.println("1 1 2 3 4 5 6 7 8 9 10");
            System.out.println("2 2 3 4 5 6 7 8 8 9 11");
            System.out.println("3 3 4 5 6 7 8 8 9 10 11 12");
            System.out.println("4 4 5 6 7 8 9 10 11 12 13");
            System.out.println("5 5 6 7 8 9 10 11 12 13 14");
            System.out.println("6 6 7 8 9 10 11 12 13 14 15");
            System.out.println("7 7 8 9 10 11 12 13 14 15 16");
            System.out.println("8 8 9 10 11 12 13 14 15 16 17");
            System.out.println("9 9 10 11 12 13 14 15 16 17 18");
     
     
        }
        public static void printTrigTables (double a1, double a2, double a3, double a4,
                double a5, double a6, double a7, double a8, double a9, double a10, double a11,
                double a12) {
            // Need to print sin, cos, tan of angles between 0-360
            // in 30 degree increments
            // Radians = Degrees * PI / 180
     
     
     
            System.out.print("Angle 30");
            a1 = 30 * 2 * Math.PI/360;
            System.out.println ("cos(" + a1 + ") is " + Math.acos(a1));
            System.out.println ("sin(" + a1 + ") is " + Math.asin(a1));
            System.out.println("tan(" + a1 + ") is " + Math.atan(a1));
            System.out.print("Angle 60");
            a2 = 60 * 2 * Math.PI/360;
            System.out.println("cos(" + a2 + ") is " + Math.acos(a2)) ;
            System.out.println("sin(" + a2 + ") is " + Math.asin(a2));
            System.out.println("tan(" + a2 + ") is " + Math.atan(a2));
            System.out.print("Angle 90");
            a3 = 90 * 2 * Math.PI/360;
            System.out.println("cos(" + a3 + ") is " + Math.acos(a3)) ;
            System.out.println("sin(" + a3 + ") is " + Math.asin(a3));
            System.out.println("tan(" + a3 + ") is " + Math.atan(a3));
            System.out.print("Angle 120");
            a4 = 120 * 2 * Math.PI/360;
            System.out.println("cos(" + a4 + ") is " + Math.acos(a4));
            System.out.println("sin(" + a4 + ") is " + Math.asin(a4));
            System.out.println("tan(" + a4 + ") is " + Math.atan(a4));
            System.out.print("Angle 150");
            a5 = 150 * 2 * Math.PI/360;
            System.out.println("cos(" + a5 + ") is " + Math.acos(a5));
            System.out.println("sin(" + a5 + ") is " + Math.asin(a5));
            System.out.println("tan(" + a5 + ") is " + Math.atan(a5));
            System.out.print("Angle 180");
            a6 = 180 * 2 * Math.PI/360;
            System.out.println("cos(" + a6 + ") is " + Math.acos(a6));
            System.out.println("sin(" + a6 + ") is " + Math.asin(a6));
            System.out.println("tan(" + a6 + ") is " + Math.atan(a6));
            System.out.print("Angle 210");
            a7 = 210 * 2 * Math.PI/360;
            System.out.println("cos (" + a7 + ") is " + Math.acos(a7));
            System.out.println("sin (" + a7 + ") is " + Math.asin(a7));
            System.out.println("tan (" + a7 + ") is " + Math.atan(a7));
            System.out.print("Angle 240");
            a8 = 240 * 2 * Math.PI/360;
            System.out.println("cos (" + a8 + ") is " + Math.acos(a8));
            System.out.println("sin (" + a8 + ") is " + Math.asin(a8));
            System.out.println("tan (" + a8 + ") is " + Math.atan(a8));
            System.out.print("Angle 270");
            a9 = 270 * 2 * Math.PI/360;
            System.out.println("cos (" + a9 + ") is " + Math.acos(a9));
            System.out.println("sin (" + a9 + ") is " + Math.asin(a9));
            System.out.println("tan (" + a9 + ") is " + Math.atan(a9));
            System.out.print("Angle 300");
            a10 = 300 * 2 * Math.PI/360;
            System.out.println("cos (" + a10 + ") is " + Math.acos(a10));
            System.out.println("sin (" + a10 + ") is " + Math.asin(a10));
            System.out.println("tan (" + a10 + ") is " + Math.atan(a10));
            System.out.print("Angle 330");
            a11 = 330 * 2 * Math.PI/360;
            System.out.println("cos (" + a11 + ") is " + Math.acos(a11));
            System.out.println("sin (" + a11 + ") is " + Math.asin(a11));
            System.out.println("tan (" + a11 + ") is " + Math.atan(a11));
            System.out.print("Angle 360");
            a12 = 360 * 2 * Math.PI/360;
            System.out.println("cos (" + a12 + ") is " + Math.acos(a12));
            System.out.println("sin (" + a12 + ") is " + Math.asin(a12));
            System.out.println("tan (" + a12 + ") is " + Math.atan(a12));
     
     
        }
     
        ;
     
     
    }


  2. #2
    Member
    Join Date
    Sep 2012
    Posts
    98
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Printing from a Method

    Any idea of why it's not picking that up?

  3. #3
    Junior Member
    Join Date
    Apr 2012
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Printing from a Method

    Does the program finish running, or does it hang? Also, you seem to have a rogue ; floating in limbo.

  4. #4
    Member
    Join Date
    Sep 2012
    Posts
    98
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Printing from a Method

    Yeah I fixed the ; , but it does finish running. It doesn't act as though its picking up the call in main.

  5. #5
    Junior Member
    Join Date
    Apr 2012
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Printing from a Method

    The code looks like it should work to me, perhaps try adding System.out.flush() at the end to make sure its not stuck in stdout... Are you running it in an IDE or on the command line?

  6. #6
    Member
    Join Date
    Sep 2012
    Posts
    98
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Printing from a Method

    Im running it in netBeans IDE, flush didn't seem to help, any other ideas? :/

  7. #7
    Member
    Join Date
    Mar 2011
    Posts
    66
    My Mood
    Relaxed
    Thanks
    12
    Thanked 4 Times in 4 Posts

    Default Re: Printing from a Method

    Quick question about your sin, cos, and etc, you're using Math.a[....] which is the arc[....]. Were you intending this? or did you just want Math.cos and etc?

  8. #8
    Member
    Join Date
    Sep 2012
    Posts
    98
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Printing from a Method

    Ill change that atm Act.

  9. #9
    Member
    Join Date
    Sep 2012
    Posts
    98
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Printing from a Method

    Still didn't change any output.

  10. #10
    Junior Member
    Join Date
    Apr 2012
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Printing from a Method

    must say I am at a loss. Ill try running it for myself later(when Im at home) if you haven't figured it out by then. You don't need to be declaring all those doubles in main, but that wouldn't effect printl.

  11. #11
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Printing from a Method

    Works for me...I'd suggest deleting the current class file, recompile, and then run the new class file.

  12. #12
    Member
    Join Date
    Sep 2012
    Posts
    98
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Printing from a Method

    Thanks copeg, it worked for some reason if I just deleted it all

Similar Threads

  1. Printing data from a method
    By LoganC in forum What's Wrong With My Code?
    Replies: 10
    Last Post: September 23rd, 2012, 06:51 AM
  2. Calling a print method from another class (printing array)
    By Kaldanis in forum Object Oriented Programming
    Replies: 7
    Last Post: November 25th, 2011, 01:32 PM
  3. Replies: 1
    Last Post: September 28th, 2011, 07:29 AM
  4. Printing Job
    By qwerty53 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: July 19th, 2011, 08:34 AM
  5. [SOLVED] Printing Array without printing empty elements
    By CarlMartin10 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 12th, 2010, 02:41 AM