Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

multiplication table using while loops and do-while loops

843785Feb 23 2009 — edited Feb 23 2009
I recieved help on the first part of my original problem yesterday but am now even more confused on the second part... i need this program to make a multiplication table that shows the multiples of 9-17 vertically and horizontally. case 1 of my switch works but cases 2 (while loop) and case 3( do-while loops) are giving me some problems. if anyone can explain why i recieve no output on case 2 and direct me towards how to fix it i would appreciate it...thanks.

import java.io.*;

public class multtbl
{

public static void main(String args[])
{
int loop = 5;
int j = 0;
int i = 0;
String t= "";
System.out.print("type 1 for loop type 2 for while loop type 3 for do loops ");

BufferedReader stdin1 =new BufferedReader(new
InputStreamReader(System.in));

{
try {
t = stdin1.readLine();
}catch(java.io.IOException exp){ exp.printStackTrace();}



loop = Integer.parseInt(t);

System.out.println("");
}


switch(loop){
case 1:
	for (i = 9; i <= 17; i++){
		System.out.println();
			for (j = 9; j <= 17; j++){

			System.out.printf("%4d", i * j);

}}
case 2:
	 i = 9;
	 j = 9;
		while (i <= 17);{
			System.out.print(i * j); i++;

	while (j <=17);{
	System.out.print(i * j);
	j++;


}}
case 3:
	 i = 9;
	 j = 9;
	do {System.out.printf("%4d", i * j);
	i++;}
	while (i <= 17);
System.out.println();

	 do {System.out.printf("%4d", i * j);
	j++;}
	while (j <=17);


}}}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 23 2009
Added on Feb 23 2009
29 comments
1,204 views