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 2 of 2

Thread: Java program, nested for loop help

  1. #1
    Junior Member
    Join Date
    Sep 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java program, nested for loop help

    Hello so I am working on my java program it prints out a table of angles and the sin, cos, and tan. For extra credit he wanted us to use nest loops to create a space after every five lines. I have come real close to getting this to work but have a problem with the very end of the table. The table needs to stop at 180
    	public static void printTable(double angle,double sin,double cos,double tan) {   // Method to create a table for the values
     
    		for (double j = 0; j <= 180;) {						
     
    			for (double i = 1; i <= 5; i++) {					//loop to print five lines of code
     
    			angle = Math.toRadians(j);
     
    			sin = round4(Math.sin(angle));
    			cos = round4(Math.cos(angle));
    			tan = round4(Math.tan(angle));
     
     
    			System.out.println(round4(j) + "\t" + sin + "\t" + cos + "\t" + tan);
     
    			j = j +1; 
    				}
     
    			System.out.println();
    			}
    		}

    here is the end of the output of the table:
     
    175.0	0.0872	-0.9962	-0.0875
    176.0	0.0698	-0.9976	-0.0699
    177.0	0.0523	-0.9986	-0.0524
    178.0	0.0349	-0.9994	-0.0349
    179.0	0.0175	-0.9998	-0.0175
     
    180.0	0.0	-1.0	0.0
    181.0	-0.0175	-0.9998	0.0175
    182.0	-0.0349	-0.9994	0.0349
    183.0	-0.0523	-0.9986	0.0524
    184.0	-0.0698	-0.9976	0.0699
    Last edited by cwebz; October 1st, 2014 at 08:43 PM.


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Java program, nested for loop help

    OP marked it solved.

Similar Threads

  1. nested while loop
    By Amruta N in forum What's Wrong With My Code?
    Replies: 3
    Last Post: September 2nd, 2013, 12:35 AM
  2. Need help with this nested loop
    By beerye28 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 22nd, 2013, 09:51 PM
  3. [SOLVED] Java nested loop
    By maple1100 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 14th, 2013, 09:27 PM
  4. Nested For Loop!
    By samadniz in forum Object Oriented Programming
    Replies: 3
    Last Post: September 3rd, 2012, 04:03 PM
  5. Need help with java gui and nested for loop
    By gatorsgirl in forum Loops & Control Statements
    Replies: 11
    Last Post: March 24th, 2012, 12:35 PM