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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:49:20+00:00 2026-06-14T07:49:20+00:00

im doing a program where i need to return the index of MyString of

  • 0

im doing a program where i need to return the index of MyString of the first occurence.
idk how to use the indexof in this situation. i think it might be something like
ch = indexof[] but im not sure. im still new at this and the api didnt help me much

/*********************************************************************************
     This program will create classes that do similar operations to the Java String

     Javier Perez
     csc110
     11/5/12
    *********************************************************************************/
    package string.assignment;
    public class MyString
    {

        private char[] array;
        private int size;
        private int max;

        public MyString()
        {
            array = new char[25];
            max = 25;
        }
        public void setString(String newString)
        {
         if(newString.length() > 25)
         {
             System.out.println("/nEnter a number equal or less than 25 " );

         }
         else
         {
          for(int i=0; i < newString.length(); i++)
          {
            array[i] = newString.charAt(i);
          }
         }
        }


        public String toString()
        {
            return new String(array);
        }

        public char charAt(int index)
        {
            return array[index];
        }

        public boolean contains(char ch)
        {
            for(char c: array)
            {
                if(c == ch) return true;
            }
            return false;
        }
        public int indexOf( char ch )
        {
            ch = ch.indexOf();

        }
        return index; 


    }
  • 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-14T07:49:21+00:00Added an answer on June 14, 2026 at 7:49 am

    For fetching the index of a certain character from your array, you would have to iterate over the array, and compare each character with the one you want to check. If any character matches, return the index immediately.

    Also, your last return statement should be inside your method, else your code would not compile.

    So, your indexOf method in its simplest would be like this: –

    public int indexOf( char ch ) {
        for (int i = 0; i < array.length; i++) {
            if (array[i] == ch) {
                return i;   // Character found, return current index
            }
        }
        return -1;    // Character not found. Return -1
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm doing a theatrical performance, and I need a program that can read images
I'm doing my program in many steps. One of them is to use gevent
I am doing a minesweeper program for school, but i keep getting this error
This program I'm doing is about a social network, which means there are users
I am a beginner in developing iPhone applications. I was doing this sample program
I'm doing an expression valuation program, just like this . My problem is that
I need some help making this program for class. We are working with g++
I want to use Decimal class in my Python program for doing financial calculations.
I am new to python and doing this homework. I need to create a
I'm trying to update this Listbox in C#. This is my first program in

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.