A community for students.
Here's the question you clicked on:
 0 viewing
pottersheep
 4 years ago
Please explain this part of the method program for me? (simple beginner program)
pottersheep
 4 years ago
Please explain this part of the method program for me? (simple beginner program)

This Question is Closed

pottersheep
 4 years ago
Best ResponseYou've already chosen the best response.0import 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= ty; } 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= ty; } static int c(int t,int y){ return result= t*y; } static int d(int x,int y){ return result= x/y; } "

pottersheep
 4 years ago
Best ResponseYou've already chosen the best response.0static int result=0; ?? What is that ?? a method?? why couldnt i initialize it above??

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0It's a class variable. You can't declare it in main and then use it from your "a,b,c,d" methods.

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0Nope, class variable. They're different.

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0class variable in other words is called global variable because it can be accessed in whole class
Ask your own question
Sign UpFind more explanations on OpenStudy
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
 Engagement 19 Mad Hatter
 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.