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

Thread: Multiplication code

  1. #1
    Junior Member
    Join Date
    Dec 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Multiplication code

    Hello,
    Please i need help in writing code for multiplications of any number by 2 to 8.. I am using Eclipse.
    So that when ever you typed a number and hit enter, it will multiply from 2 to 8.

    Example: When you type 14 and hit enter after saving and run the code, you get this.
    14 x 2 = 28
    14 x 3 = 42
    14 x 4 = 56
    14 x 5 = 70
    14 x 6 = 84
    14 x 7 = 98
    14 x 8 = 112


    Thanks for your help


  2. #2
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Location
    Wales, Bangor & England, Warwickshire
    Posts
    820
    My Mood
    Cynical
    Thanks
    7
    Thanked 104 Times in 90 Posts

    Default Re: Multiplication code

    Firstly welcome to Java Program Forums
    Secondly, I have moved your post to a more appropriate forum.

    Thirdly, what code have you got so far? Better to get stuck in then come to use for help than ask us to do it for you.

    You will get good and helpful responses as soon as you post some code that shows you've given it a bash

    Thanks,
    Chris
    chris[at]javaprogrammingforums[dot]com

    Prifysgol Bangor University, North Wales

  3. #3
    Member goldest's Avatar
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    63
    Thanks
    1
    Thanked 12 Times in 10 Posts

    Wink Re: Multiplication code

    In case if you are totally chocked up about how to get started, here are some pointers.

    1) Use chained stream readers to get the console input.

    2) Read the console input into a String.

    3) Convert that String into a number using the Integer wrapper class.

    4) Have a for loop, get an integer ranging from 2 to 8.

    5) Multiply that loop integer with the console number and display the result of each iteration.

    Try it out and let us know what have you achieved so far...

    Hope that helps,

    Goldest
    Java Is A Funny Language... Really!

    Sun: Java Coding Conventions

    Click on THANKS if you like the solution provided.
    Click on Star if you are really impressed with the solution.

  4. #4
    Member
    Join Date
    Dec 2010
    Posts
    46
    Thanks
    0
    Thanked 10 Times in 10 Posts

    Default Re: Multiplication code

    import java.util.Scanner;
    public class MultiplicationTable {
        public static void main(String[] args){
            int input=0;
            System.out.print("Enter a number: " );
            Scanner keyboard  = new Scanner(System.in);
            ******  fill in the missing code here *******
            for(int i=2; i<=8 ; i++){
                System.out.println( input + " * " + i + " =  " + (input * i) );
            }
            keyboard.close();
        }
    }

  5. #5
    Member goldest's Avatar
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    63
    Thanks
    1
    Thanked 12 Times in 10 Posts

    Wink Re: Multiplication code

    This is what I was thinking about,

    import java.io.*;
     
    public class MultiplicationTest {
     
    	public static void main(String args[]) {
    		System.out.print("Enter Number: ");
    		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
     
    		try {
    			int number = Integer.parseInt(br.readLine());
    			for (int x = 2; x < 9; x++) {
    				System.out.println(number + " * " + x + " = " + (x * number));
    			}
    		} catch (IOException io) {
    			io.printStackTrace();
    		}
    	}
    }
    Goldest
    Java Is A Funny Language... Really!

    Sun: Java Coding Conventions

    Click on THANKS if you like the solution provided.
    Click on Star if you are really impressed with the solution.

Similar Threads

  1. Having problem in matrix multiplication....
    By sidhant in forum Java Theory & Questions
    Replies: 5
    Last Post: March 17th, 2011, 02:41 PM