Results 1 to 5 of 5
  1. #1
    SwEeTAcTioN's Avatar
    SwEeTAcTioN is offline Member
    Join Date
    Oct 2009
    Posts
    69
    Rep Power
    0

    Default Multiplication Table

    So i have been gone off the forums for about 9 months or so for various reasons i rather not discuss and this is my first post back so some quick help would be fantastic

    So I have this program
    Java Code:
    package hello;
    import java.io.*;
    public class hello2 {
    public static void main(String[] args)throws IOException
    {
    	BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
    	int strt=Integer.parseInt(input.readLine());
    	int end=Integer.parseInt(input.readLine());
    	int Num_Of_Multiples=Integer.parseInt(input.readLine());
    	int bcnt=0;
    	int cnt=1;
    	
       while(bcnt<end)
       {
        bcnt++;	
    		for(cnt=0; cnt<Num_Of_Multiples; cnt++);
    		{
    		   System.out.print(cnt*Num_Of_Multiples+" ");
    		}
    	} 
        System.out.println();
        System.out.println(cnt);
        System.out.println(Num_Of_Multiples);
        System.out.println(bcnt);
        System.out.println(strt);
        System.out.println(end);
        
    		
    			
    	
    	
    }   
      
    }
    And my problem is that i need it to do something like this
    Java Code:
    2 4 6 8 10
    3 6 9 12 15
    4 8 12 16 20 etc...Depending on what strt and end are and Num_Of_Multiples controlss how many times it multiplies before going to the next row
    And i am just getting
    Java Code:
    2//strt //what i entered
    4//end //what i entered
    5//Num_Of_Multiples //what i entered
    25 25 25 25 // output
    5//cnt
    5//Num_Of_Multiples
    4//bcnt
    2//strt
    4//end
    And i have no earthly idea of what is going on can anyone help me out

    All help is appreciated:)
    Are you suggesting that Cocunuts migrate?!! -Monty Python

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    For one thing, this semicolon is making your for loop useless:
    Java Code:
          for (cnt = 0; cnt < Num_Of_Multiples; cnt++); // <==== this semicolon ****
          {
            System.out.print(cnt * Num_Of_Multiples + " ");
          }
    For another you'll need to work out the basic math involved here. Plan to use a lot of paper and a pencil and you will solve it, since I know you've got the brain power to do it.

    Much luck!

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    hint: are you sure you want bcnt to start at 0?

  4. #4
    SwEeTAcTioN's Avatar
    SwEeTAcTioN is offline Member
    Join Date
    Oct 2009
    Posts
    69
    Rep Power
    0

    Default

    ah crap the dang semicolon i havent programmed in java i a while and i forgot some syntax and i have the math now thanks for pointing out the semicolon:)
    Are you suggesting that Cocunuts migrate?!! -Monty Python

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Quote Originally Posted by SwEeTAcTioN View Post
    ah crap the dang semicolon i havent programmed in java i a while and i forgot some syntax and i have the math now thanks for pointing out the semicolon:)
    Sometimes you need to just walk away from the code for a while to see it anew.

    You're welcome and I'm sure I speak for all when I say welcome back!

Similar Threads

  1. Multiplication table quiz
    By wolfy101 in forum New To Java
    Replies: 1
    Last Post: 11-16-2009, 06:29 AM
  2. Multiplication table
    By rjones215 in forum New To Java
    Replies: 3
    Last Post: 10-19-2009, 04:34 PM
  3. Replies: 2
    Last Post: 02-23-2009, 02:18 AM
  4. Help with Multiplication
    By phil028 in forum New To Java
    Replies: 1
    Last Post: 12-06-2007, 07:39 PM
  5. Help with multiplication table
    By Albert in forum New To Java
    Replies: 1
    Last Post: 07-10-2007, 04:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •