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

The Archive Base Latest Questions

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

I am trying to write a method that can take a starting lowercase letter

  • 0

I am trying to write a method that can take a starting lowercase letter and an ending lowercase letter and generate random letters in that range. Next, the random letters are assigned to the elements of an array of a size determined by the user. So far, my code seems to work as long as the starting character is ‘a’. I can’t figure out how to make it work when the starting character is not ‘a’. I wrote this complete program to try to troubleshoot my method:

import java.util.Random;
import java.util.Scanner;
public class Add
{
    public static void main( String[] args )
    {
        Scanner scan = new Scanner(System.in);
        System.out.print("Enter array size: ");
        int arraySize = scan.nextInt();
        char charArray[] = new char[arraySize];

        int fromChar;
        int toChar;
        do
        {
        System.out.print("Enter first character: ");
        String line = scan.next();
        fromChar = line.charAt(0);

        System.out.print("Enter second character: ");
        line = scan.next();
        toChar = line.charAt(0);

        Random generator = new Random();
        for(int i = 0; i < arraySize; i++)
        {
            int randomInt = generator.nextInt(toChar - fromChar + 1) + 97;
            //System.out.print(randomInt + " | "); //used to print unicode values
            charArray[i] = (char)(randomInt);
        }
        System.out.println(charArray);
    }
        while(true);

    } // end of main
}// end of class

Any help would be greatly appreciated!

  • 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:43:45+00:00Added an answer on June 14, 2026 at 4:43 am
    int randomInt = generator.nextInt(toChar - fromChar + 1) + fromChar;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write (or just find an existing) PHP method that can take
I'm trying to write a method that will take in two Queues (pre-sorted Linked
I'm trying to write a method that will compute all permutations of a power
I am trying to write a method that adapts to different types of interfaces
I'm trying to write a method that removes all non alphabetic characters from a
I'm trying to write a method that acts as a setter and takes some
I am trying to write a method that makes a log.txt file if one
I am trying to write a method that reads the contents of a richtext
I am trying to write a generic method that would bind any asp.net UI
I’m trying to write a regex/method that extracts Variables from an input String that

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.