PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, August 18, 2022

[FIXED] How to println value from function?

 August 18, 2022     java, output, void     No comments   

Issue

I would like to println value 5 from void add_up but I cant write name of function: add_up to System out.println(). How to println out of main and get out of void add_up? Thank´s.

import java.io.IOException;

public class function{

    public static void main(String[] args) throws IOException {

            System.out.println(add_up);

    }

    public int add_up(){
    int a = 5;
    return a;
    }
}


Solution

In order to call the method you need to add () after its name.

import java.io.IOException;

public class Function {

    public static void main(String[] args) {
      System.out.println(add_up());
    }

    public static int add_up(){
      int a = 5;
      return a;
    }
}

Secondly, you needed to make your method static so the static method main can access it.



Answered By - CausingUnderflowsEverywhere
Answer Checked By - Senaida (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing