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

  • Home
  • SEARCH
  • 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 9241389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:21:50+00:00 2026-06-18T08:21:50+00:00

Consider this code: private static void colourRead(String s) throws IOException { FileReader readhandle =

  • 0

Consider this code:

private static void colourRead(String s) throws IOException {
    FileReader readhandle = new FileReader("C:\\****\\****");
    BufferedReader br = new BufferedReader(readhandle);
    String line = null;
    while ((line = br.readLine()) != null) {
        ColourInput(); //there's an error here
    }

    br.close();
    readhandle.close();
}

private static void ColourInput(String s) {
    char letter;

    String fullWord;
    Scanner kb = new Scanner(System.in);

    System.out.print("Enter whatever: ");

    fullWord = kb.nextLine();
    System.out.println(fullWord);

    for (int i = 0; i < fullWord.length(); i++) {
        letter = fullWord.charAt(i);
        switch (Character.toUpperCase(letter)) {
        case 'A': {
            Blue();
        }
            break;
        }
    }
}

Is it possible for me to carry the

line

variable from the colourRead method, and somehow assign it to the

fullWord 

variable in the ColourInput() method?

I’m trying to read a text file, and output certain colours associated to each letter. I don’t want to create a new switch statement in the colourRead method because apparently, this is a bad programming practice.

Any help please?

If you’re still unsure of what I’m asking I’ll re-edit

EDIT: The problem is that after calling the ColourInput(line) method, the Scanner method comes in to work (original code). I don’t want to remove my Scanner method, I want it to ‘skip’ the scanner method, and continue into the for loop and switch statements.

  • 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-18T08:21:51+00:00Added an answer on June 18, 2026 at 8:21 am

    If I understand correctly you want to be able to repeat the functionality of the ColourInput method with the results of the the ColourRead method.

        private static void colourRead() throws IOException
    {
        FileReader readhandle = new FileReader("C:\\****\\****");
        BufferedReader br = new BufferedReader(readhandle);
        String line = null;
        while((line = br.readLine()) != null)
        {
          ColourText(line); //there's an error here
        }
    
        br.close();
        readhandle.close();
    }
    
    private static void ColourInput() 
    {
    
      String fullWord;
      Scanner kb = new Scanner(System.in);
    
      System.out.print("Enter whatever: ");
    
      fullWord = kb.nextLine();
      System.out.println(fullWord);
      ColourText(fullWord);
    }
    
    private static void ColourText(String text)
    {
    
        char letter;
        for (int i = 0; i < text.length(); i++)
        {
          letter = text.charAt(i);
          switch(Character.toUpperCase(letter))
          {
              case 'A':
              {
                 Blue();
              }
              break;
          }
    }
    

    This would let you color the text whether it is read from the file or input from the keyboard(using the ColourText method to change the color). But as other people have mentioned you should add to the file reading code as well.

    Edit: You could also remove the String s variables from the first two methods since they are not being used in the methods anywhere.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider this code: static void Main(string[] args) { var persons = new List<Person> {
Please consider this code snippet: private static void doSomething(Double avg, Double min, Double sd)
Ok, consider the following code: private const int THRESHHOLD = 2; static void Main(string[]
Consider this code: package Prova; import java.util.ArrayList; public class Prova { private ArrayList<String> people;
Consider this code snippet: public static class ApplicationContext { private static Func<TService> Uninitialized<TService>() {
Consider the following code snippet within a class private static Object _syncroot = new
Let's consider this page's code-behind: public partial class Products : Page { private static
Consider the following code: class Program { static void Main(string[] args) { A a
Consider the following code: class Program { static void Main(string[] args) { Department deathStar
Consider this code: class Foo { public void doIt(String... strs) { System.out.println(this is varargs);

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.