pottersheep
  • pottersheep
Please explain this part of the method program for me? (simple beginner program)
Computer Science
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
chestercat
  • chestercat
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
pottersheep
  • pottersheep
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; } "
pottersheep
  • pottersheep
static int result=0; ?? What is that ?? a method?? why couldnt i initialize it above??
anonymous
  • anonymous
It's a class variable. You can't declare it in main and then use it from your "a,b,c,d" methods.

Looking for something else?

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

More answers

pottersheep
  • pottersheep
global variable?
anonymous
  • anonymous
Nope, class variable. They're different.
pottersheep
  • pottersheep
ok thanks
anonymous
  • anonymous
class variable in other words is called global variable because it can be accessed in whole class

Looking for something else?

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