A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

pottersheep

  • 5 years ago

Please explain this part of the method program for me? (simple beginner program)

  • This Question is Closed
  1. pottersheep
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    import java.util.Scanner; public class methods { public static void main (String args []){ Scanner input = new Scanner (System.in); int total = 0 , first = 0 , second = 0 ; String operator; System.out.print("Enter first integer:"); first= input.nextInt(); System.out.print("Enter operator"); operator=input.next(); System.out.print("Enter second integer:"); second= input.nextInt(); if (operator.equals("+")==true) total= a(first, second); if (operator.equals("-")==true) total=b(first, second); if (operator.equals("*")==true) total=c(first, second); if (operator.equals("/")==true) total=d(first, second); System.out.print("result"+total); } static int result=0; static int a(int t,int y){ return result= t+y; } static int b(int t,int y){ return result= t-y; } static int c(int t,int y){ return result= t*y; } static int d(int x,int y){ return result= x/y; } } The part I dont understand is " *************static int result=0; static int a(int t,int y){ return result= t+y; } static int b(int t,int y){ return result= t-y; } static int c(int t,int y){ return result= t*y; } static int d(int x,int y){ return result= x/y; } "

  2. pottersheep
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    static int result=0; ?? What is that ?? a method?? why couldnt i initialize it above??

  3. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    It's a class variable. You can't declare it in main and then use it from your "a,b,c,d" methods.

  4. pottersheep
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    global variable?

  5. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Nope, class variable. They're different.

  6. pottersheep
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    ok thanks

  7. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    class variable in other words is called global variable because it can be accessed in whole class

  8. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.