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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:28:52+00:00 2026-06-18T16:28:52+00:00

so what im doing is creating a program that reads in 2 text files,

  • 0

so what im doing is creating a program that reads in 2 text files, 1 is a plain text file the other is an encrypted version of the text file.

I set the String (for every line) to uppercase and i take the char of the String index 0-65 thats where i get my position in the array.

   import java.util.Scanner;
   import java.io.File;
   import java.io.FileNotFoundException;
   public class ReadIn {
public void fileReader(){
try{
    Scanner inFile1 = new Scanner(new File("plaintext.txt"));
    //Scanner inFile2 = new Scanner(new File("ciphertext.txt"));
    int lol[] = new int[27];
    while(inFile1.hasNextLine()){
        String base = inFile1.nextLine();
        base.toUpperCase();
        String placeHolder = base;
        for(int i=0;i<base.length();i++){
            if(placeHolder.charAt(0)==' '){}
            else if(base.charAt(0)=='.'){}else if(base.charAt(0)==','){}
            else if(base.charAt(0)=='"'){}else if(base.charAt(0)==':'){}
            else if(base.charAt(0)=='-'){}else if(base.charAt(0)=='?'){}
            else if(base.charAt(0)=='!'){}else{lol[(base.charAt(0)-65)]++;}
            placeHolder = placeHolder.substring(1);
        }
    }
    for(int j=0;j<lol.length;j++){
        System.out.println(lol[j]);
        //To show what is inside the Index.
    }

    }catch(FileNotFoundException e){
        System.out.println("File is not in the correct directory!");
    }catch(ArrayIndexOutOfBoundsException e){
        System.out.println("Array Index is to small!!");
    }
  }
}

This is the output i get when i set the array size to 60

142 119 0 0 0 62 60 0 682 0 0 179 24 232 0 62 0 0 0 184 0 0 440 0 63 0 0 0 0 0 0 0 471 182 215 94 60 409 0 242 174 15 30 62 273 79 405 189 0 195 472 673 101 62 324 0 124 0 0 0

The question is, when I run the program, why is my array to small. If all letters are capitalized, then subtracting 65 from a char such as ‘A’ should be 0 and therefor add 1 to index [0] in the array.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

update

OK so i set the string to capitalize it self by “base = base = base.toUpperCase();”
This worked flawlessly except that my array has to be set at 91 to compensate for the Z (90) in ascii
when i try to go to the index point of the array to add i use [(base.charAt(0)-65)]++
but it throws ArrayIndexOutOfBoundsException -21

  • 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-18T16:28:53+00:00Added an answer on June 18, 2026 at 4:28 pm

    Your base still contains lowercase characters, as you’re not using the return value of toUpperCase(). This is confirmed by your test data: your output spans the ASCII range from 65 (A) to 122 (z), counting 58 different character codes.

    Strings in Java are immutable, their value does not change after they are constructed. Therefore, base.toUpperCase() returns a new string and does not modify the original base string. You want to replace base by its capitalized version, therefore you should override its value so it points to the returned string:

    base = base.toUpperCase();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a program (In C++) that takes an ASCII file and reads
I'm creating a small program that saves a int value into a text file,
I have a Java program that reads some text from a file, line by
I have a program that is creating multiple files. There is a function for
I'm creating a program that requires some options values to be set along with
I am creating a program that needs to store the user's data in encrypted
I'm currently creating a neighbourhood graph by doing roughly this: for every voxel look
I am creating a simple application with Django. I realized that I am doing
I'm creating a program in Excel that gets the highest and lowest numbers. I
I'm trying to write a java program that reads data from an image and

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.