Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6248917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:08:45+00:00 2026-05-24T13:08:45+00:00

How do i return an error and ask the question Do you want to

  • 0

How do i return an error and ask the question Do you want to try again (Y/N)? again when the user entered neither Y/N as an answer?

import java.io.*;

public class Num10 {
    public static void main(String[] args){
        String in="";
        int start=0, end=0, step=0;

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

        do{
            try{
                System.out.print("Input START value = ");
                in=input.readLine();
                start=Integer.parseInt(in);
                System.out.print("Input END value = ");
                in=input.readLine();
                end=Integer.parseInt(in);
                System.out.print("Input STEP value = ");
                in=input.readLine();
                step=Integer.parseInt(in);
            }catch(IOException e){
                System.out.println("Error!");
            }

            if(start>=end){
                System.out.println("The starting number should be lesser than the ending number");
                System.exit(0);
            }else
            if(step<=0){
                System.out.println("The step number should always be greater than zero.");
                System.exit(0);
            }

            for(start=start;start<=end;start=start+step){
                System.out.println(start);
            }

            try{
                System.out.print("\nDo you want to try again (Y/N)?");
                in=input.readLine();
            }catch(IOException e){
                System.out.println("Error!");
            }
        }while(in.equalsIgnoreCase("Y"));

    }
}

Should i be using if-else?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T13:08:45+00:00Added an answer on May 24, 2026 at 1:08 pm

    First +1 for supplying a fully compilable program. That’s more than 90% of question askers do.
    In your final try/catch block, check that the user entered ‘y’ or ‘n’ like this

           try{
                while (!in.equalsIgnoreCase("y") && !in.equalsIgnoreCase("n")) {
                        System.out.print("\nDo you want to try again (Y/N)?");
                        in=input.readLine();
                }
            }catch(IOException e){
                System.out.println("Error!");
            }
        }while(in.equalsIgnoreCase("Y"));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question will undoubtedly be difficult to answer and ask in a way that
Why would the following query return Error converting data type varchar to bigint? Doesn't
Short Version: Is there a/what is the suggested way to return error details to
I usually do something like the example below when I need to return error
Is it possible to have the router return an error code (or an entire
can someone please help me. why does this return an error: Dim stuff As
why does void operator<<(ostream out, Test &t); return an error whereas void operator<<(ostream &out,
How can i get IIS 7 to return my custom error pages for file
The debugger threw me this error UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:
Is it possible to get a return value other than error level from .net

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.