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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:32:04+00:00 2026-05-26T10:32:04+00:00

My name’s Ali, I have just started two units of study with the Open

  • 0

My name’s Ali, I have just started two units of study with the Open University, so I am entirely fresh-faced to Java. I am trying to get the following code to compile but the lack of support i’m getting from my tutor is horrendous and the several books I have splayed out across my room aren’t helping me get going.

I have been given a method that I wish to answer some questions about:

public char[] methodA()
{
    char[] alphas = {'s', 't', 'e', 'a', 'm'};
    char temp = alphas[0];
    int i = 0;

    while (i < alphas.length - 1)//1
    {
        alphas[i] = alphas[i+1]; //2
        i++;
    }

    alphas[alphas.length-1]=temp;

    return alphas;
}

How do I get this to compile successfully using my IDE? I have tried just enclosing it within the syntax for my ‘main’ method but it’s not accepting it.

Here is what I have at the moment:

package openuniversity;

public class Main
{
    public static void main(String[] args)
    {
        public static char[] methodA()
        {   
            char[] alphas = {'s', 't', 'e', 'a', 'm'};
            char temp = alphas[0];
            int i = 0;

            while (i < alphas.length - 1)//1
            {
                alphas[i] = alphas[i+1]; //2
                i++;
            }

            alphas[alphas.length-1]=temp;

            return alphas;
        }
    }
}

Thanks to anyone who can help.
Ali

  • 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-05-26T10:32:05+00:00Added an answer on May 26, 2026 at 10:32 am

    All methods must be enclosed within a class. If your IDE has already generated that for you, then you should be able to make it a sibling of your main method, as follows:

    public class Foo {
        public static void main(String[] args) {
            // Your main method code goes here
        }
    
        public char[] methodA() {
            char[] alphas = {'s', 't', 'e', 'a', 'm'};
            char temp = alphas[0];
            int i = 0;
    
            while (i < alphas.length - 1)//1
            {
                alphas[i] = alphas[i+1]; //2
                i++;
            }
    
            alphas[alphas.length-1]=temp;
            return alphas;
        }
    }
    

    If you wish to call methodA from your main method, you will either need to:

    • Create a new object of type Foo (by saying Foo x = new Foo())
      then invoke the method on the object you create (by saying
      x.methodA())
    • Change methodA to be static, by changing its signature to public
      static char[] methodA()
      , then invoke the method statically (by saying Foo.methodA())
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The name says it all, but to elaborate I have a list of vectors
MyModel: name = models.CharField(max_length=255) I try to sort the queryset. I just think about
[{name:Mark,Surname:Gaux}] [{Job:2,Type:Office}] I have this JSON echoed by a PHP file on the server
Name is not compliant? Layout? What? Do you have ideas what exactly could generate
What name convention the new images have to have to be loaded by the
The name of the file is \033[A.tex. Note that the filename includes two times
I have two tables with like below codes: Table: Accounts id | username |
name = namebox.getText().toString(); db.open(); Cursor c1 = db.executequery(SELECT _id FROM + DATABASE_TABLE_CUSTOMER + where
Name: <%= Html.TextBox(txtName, 20, new { @class = hello }) %> I want that
id name mydate 1 co 2011-02-10 07:25:02 2 Carl 2011-02-10 07:26:02 . . .

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.