09 June 2011 ~ 0 Comments

Example Java – Multiplications Workout

Hey guys,

Well I present one of my little coding examples that I’ve been working on – It’s very basic and does the job (I plan on adding a GUI at some point). What it does is allow you to enter a number such as 7, and then displays the 7 times table! It uses a for loop to increment the times table and display the result.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//Work out the times tables of what is inputted
import java.util.*;
public class TimesTable {</code>

<code>public static void main(String[] args) {</code>

<code>int num, result;
Scanner keyboard = new Scanner(System.in);
System.out.println("***Times Tables***");
System.out.println("What Times Table would you like? ");
num = keyboard.nextInt(); //input number
System.out.println("Times Table of " + num + " is :");
//start the for loop
for (int a = 1; a <= 12; a++) //go up to 12 with loop
{
System.out.print( + a  + " x " + num); //display the multiplication
result = num * a;  // work out the result
System.out.println(" = " + result); //display result
}
}
}

Looking for any comments on how to make it better :-)

Be Sociable, Share!

Related posts (By Relevance):

  1. Basic Computer Ordering – Java
  2. User sum test – Java
  3. Child Discount – Java Example

Leave a Reply

show
 
close
#oGame still play it after so many years, if anyone is #bored give it a go http://t.co/3HKrOZtR