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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:57:04+00:00 2026-05-30T17:57:04+00:00

I have errors when I run program(1). But when I used program(2), writing 0

  • 0

I have errors when I run program(1). But when I used program(2), writing 0 after a, it run and produced the correct output. Writing 0, is just my guess and somehow it worked. Why is that?

Program (1):

    public static void main(String[] args) {

        System.out.println(a);

    }

    private static int a(int len) {
        String s = "What";
        len = s.length();
        return (len);
    }
}

Program (2):

 public static void main(String[] args) {

        System.out.println(a(0));

    }

    private static int a(int len) {
        String s = "What";
        len = s.length();
        return (len);
    }
}
  • 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-30T17:57:05+00:00Added an answer on May 30, 2026 at 5:57 pm

    You wrote the function in such a way that it requires a parameter. To call a function that requires a parameter, you have to supply one. That’s why the second program worked–you gave the function a a parameter of 0.

    To make the first program work, then, you have two options. The first is what you did–supply the required parameter for the function. The second is to modify the function declaration so it does not require a parameter, changing

    private static int a(int len) {
    

    to

    private static int a() {
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have used Inserts, selects, updates, deleted without problem all over the program but
I have created this code, and when I run it, don't get any errors
I have custom errors configured in my web.config, but IIS 6.0 is returning the
I wrote this code I have these errors Cannot implicitly convert type x.Program.TreeNode' to
I'm not sure why this isn't working. I don't have any errors, but what
I have some HTML errors in my output source code, coming from one of
I am writing a program which is targeted to run on .net framework 2.0.
I have just started learning XNA. This is my first program that I am
The problem: I can't get my java app to run after compiling. My guess
I have successfully written a video processing program. I used ubuntu and Netbeans for

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.