Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to repeat code until user wants to quit?

 
ics noob
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 216
Java Linux Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic