This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes How to repeat code until user wants to quit? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to repeat code until user wants to quit?" Watch "How to repeat code until user wants to quit?" New topic
Author

How to repeat code until user wants to quit?

ics noob
Greenhorn

Joined: Oct 01, 2012
Posts: 1
How do I repeat this until the user wants to quit?

import java.util.Scanner;
public class multi
{

public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
int n;
System.out.println("Enter # here for a #*# table");
n = keyboard.nextInt();




System.out.print(" |");
for (int j = 1; j <= n; j++)
System.out.print(" " + j);
System.out.print('\n');
System.out.print(" ");
for (int i= 0; i<n; i++)
System.out.print("---");
System.out.println("");
for (int i = 1; i <= n; i++)


{
System.out.print(" " + i + "|");
for (int j = 1; j <= n; j++)
{
String display = "";

if (i * j < 10)
{
display += " " + i * j;
System.out.print(display);
}
else
{
display += " " + i * j;
System.out.print(display);
}
}
System.out.print('\n');
}
}

}
Nikhil Sagar
Ranch Hand

Joined: Apr 21, 2012
Posts: 216

do pham wrote:Hi everybody,
I'm a new user of this forum.


Welcome back do pham to the coderanch.
May be you would like to have a look at HowToAnswerOnJavaRanch and HowToAskQuestionsOnJavaRanch before post

OCPJP 6 86%
 
 
subject: How to repeat code until user wants to quit?
 
Similar Threads
program that prints the multiplication table up to one
Help
diamond pattern without parse.int (Someone help me T.T) :cry:
using for loops in calculations
Search Element in array Problem