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 8815501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:23:44+00:00 2026-06-14T04:23:44+00:00

I want to ask you how to make It when proccess and do this

  • 0

I want to ask you how to make It when proccess and do this again. I mean when program did his work It must to ask: Do you want search for other word, Yes or No? If Yes program will start again, if no exit.

I think about:

 int searchAgain = 0;
            System.out.println("Do you want search for other word?");
            System.out.println("1=Yes 2=No");
            searchAgain = input.nextInt();}
        else {
            System.out.println("Error...");
            }   
                if (searchAgain == 1) {
                    System.out.println("Write your word: ");
                    .....//I dont know what here

                }
                    else{
                        System.out.println("Program closed.");
                    }

This is my current code:

    package lt.kvk.i3_2.kalasnikovas_stanislovas;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;


public class Miestai {


        public static void main(String args[]) throws Exception {
            String kitasStilius = "";
            while (!"Ne".equalsIgnoreCase(kitasStilius )) {
            Scanner input = new Scanner(System.in);
            System.out.println("Pasirinkite muzikos stiliu is saraso:");
            System.out.println();

            try {

                FileReader fr = new FileReader("src/lt/kvk/i3_2/kalasnikovas_stanislovas/Stiliai.txt");
                BufferedReader br = new BufferedReader(fr);
                String stiliuSarasas;
                while((stiliuSarasas = br.readLine()) != null) {
                    System.out.println(stiliuSarasas);
                }
                fr.close();
                String stilius = input.nextLine();   
                BufferedReader bf = new BufferedReader(new FileReader("src/lt/kvk/i3_2/kalasnikovas_stanislovas/Miestai.txt"));
                int counter = 0;                
                String line;

                System.out.println("Ieskoma informacija apie " + stilius);
                ArrayList<String> miestuSarasas = new ArrayList<String>();
                String miestas = null;

                while (( line = bf.readLine()) != null){
                    if (line.trim().length() == 0) miestas = null;
                       else if (miestas == null) miestas = line;
                       int indexfound = line.indexOf(stilius);
                       if (indexfound > -1) {
                       counter++;
                       miestuSarasas.add(miestas);
                       }                   
                }
                if (counter > 0) {
                    System.out.println(stilius + " turi " + counter + " remejus: " + miestuSarasas);                    
                    System.out.println("Ar norite ieskoti informacijos apie kita stiliu?");
                    System.out.println("Iveskite: Taip arba Ne");
                    kitasStilius = input.next();

                    }
                else {
                    System.out.println("Klaida, nerastas muzikos stilius");
                    break;
                    }   
                        if ("Taip".equalsIgnoreCase(kitasStilius)) {
                        }
                        else if ("Ne".equalsIgnoreCase(kitasStilius)) {
                            System.out.println("Darbas baigtas.");

                        }
                            else{
                                System.out.println("Neteisingai pasirinkta.");
                                break;
                            }
                        bf.close();
                        }

            catch (IOException e) {
                System.out.println("Error:" + e.toString());
            }
        }
        }
        private void searchWord(String textToSearch ){
            //your logic here which performs the search and prints the result
         }
     }

Program counting words (entered by keyboard) from file.txt and elect who repeated this word for ex.: if I enter word: One It shows:

Word One repeated 3 times by John, Elisa, Albert

file.txt looks like:

John //first line - name
One
Three
Four

Peter //first line - name
Two
Three

Elisa //first line - name
One
Three

Albert //first line - name
One
Three
Four

Nicole //first line - name
Two
Four

Thank you for answers.

  • 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-06-14T04:23:45+00:00Added an answer on June 14, 2026 at 4:23 am

    Wrap your code(slightly modified) in a while loop with condition on searchAgain as:

    EDIT: Updating to accept the option as String:

     public class Testing {
    
       public static void main(String args[]) throws Exception {
           Scanner input = new Scanner(System.in);
            System.out.println("Select word from list:");
            System.out.println();
    
            String searchAgain = "";
            while(!"No".equalsIgnoreCase(searchAgain )){
               System.out.println("Do you want search for other word?");
               System.out.println("Enter: Yes or No");
               searchAgain = input.next();
               if ("Yes".equalsIgnoreCase(searchAgain)) {
                  System.out.println("Write your word: ");
                  String textToSearch = input.next();
                  searchWord(textToSearch );
               } else if ("No".equalsIgnoreCase(searchAgain)) {
                     System.out.println("Program closed.");
               } else{
                     System.out.println("Invalid Input.");
               }
            }
         }
    
         private void searchWord(String textToSearch ){
            //your logic here which performs the search and prints the result
         }
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to ask if is there any faster method how to make this
I want to ask you something. I make the application web with the Google
I want to make a little php poll. The script should ask the users
I want to ask a question about UITableViewCell. Apparently, this is what I want
I want to ask that, is it possible to make any cover opening effect
I want to ask quick question, i want to make a select drop down
I want to ask how to make my urls to include the worh that
I'd just want to ask how to make a page list, like [First][1][2][3][4][Last]. When
Here is what I want to ask: I want to make a system to
I want to ask if it is good practice to make a class create

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.