Header Ads

Do You Want To Continue Yes or No in Java. User Want to Continue Program in Java

Do You Want To Continue Yes or No in Java. User Want to Continue Program in Java






User Need to Add Loop So it Asks To User Do You Want to Continue Program Again and again. When User Test Program Then User want to Test Another Task. Program ask the user to Do You Want to Continue (Y/N). If user Press “Y” then program Check another Task. But if User Press Any Other Key the Program Terminate.


Code Example:

import java.util.*;

public class Test {

public static void main(String[] args) {
  Scanner sc = new Scanner(System.in);
  char choice;
  do {
  int i, t;
  System.out.println("Enter Table Number:");
  t = sc.nextInt();
  i = 1;
  while(i <= 10) {
  System.out.println(i + "*"+ t + "=" + i*t);
  i++;
  }
  System.out.println("Do You Want To Continue(Y/N)");
  choice = sc.next().charAt(0);
  
  } while(choice == 'Y'|| choice == 'y');
}

Output

Do, You, Want, Continue, Yes, No,Java,Program,
Do You Want, To Continue Yes or No, in Java,User Want to Continue, Program in Java,
Do You Want To Continue Yes or No in Java,User Want to Continue Program in Java,


1 comment:

Powered by Blogger.