java - How do I pass an int from my main to method for calculations? -
Trying to create a program where the user inputs 2 numbers in my head, the menu method shows that Depending on what the user wants to do using those two numbers using a switch statement, then 4 other methods will be based on the option of selecting from the menu based on calculations.
My problem / question is how can I pass my 2 stored entities from my main collection to calculate in my other 4 ways?
My solution was to ask in my menu method and transfer the process of inputting 2 integers, but my instructor specifically asked to pass the inputs in the main ways.
Even what I have so far edit I know that this code compiles and works, which I It was supposed to have 5 links code that asks 2 integers in my head instead of my menu method EDIT When I move my main (Input 2 integers), I get the load of most errors "symbols on all my methods Can not find example: I am assuming this because the int is correctly executed by my methods But I have had a loss, how to do it Pass the number as the parameter
public static zero main String [] args) {scanner KB = new scanner (System.in); // Keyboard input allows input from the menu; // menu catches System.out.print ("\ n \ nPress ENTER to continue"); Kb.nextLine (); Iainmen = Menu (); // call menu method} public static int menu () {int INUM1; // Uses User Input for Number 1 Int INum2; // # 2 scanner cat captures the user input = kb = new scanner (System.in); // allows input from keyboard system.out.print ("\ nPlease enter integer first:"); INum1 = kb.nextInt (); System.out.print ("\ nPlease enter another integer:"); INum2 = kb.nextInt (); Int iSelection; // Catch the menu selection system Out.println ("\ n \ t MENU"); "+ \ N1> The sum of two integers" + "\ n2> Find the difference between the two integers" + "\ n3> Average searches for the two integers" + "\ n4> 2 integers Find the product "+" \ N5> Get excerpts of two integers "); ISelection = kb.nextInt (); //} switch (iSelection) {Case 1: sumTwoNumbers (iNum1, iNum2); break; Case 2: Sub-number 2 (iNum1, iNum2); break; Case 3: Average number two (iNum1, iNum2); break; Case 4: Multitube Dubs (iNum1, iNum2); break; Case 5: divTwoNumbers (iNum1, iNum2); } Return iSelection; // End Menu ()} Public Fixed In sumTwoNumbers (int iNum1, int iNum2) {int iSum; // iNum1 and iNum2 holds the sum iSum = iNum1 + iNum2; Println (iSum); Return iSum; // And Same Two Dubs (Int, Int)} Public Fixed In Sub-To-Dash (Int. INum1, Int INum2) {int iSub; // INUM1 and iNum2 difference difference iSub = iNum1 - iNum2; Println (iSub); Return iSub; // end subTwoNumbers (int, int)} public static double avgTwoNumbers (int iNum1, int iNum2) {double dAvg; // iNum1 and iNum2 average of dAvg = (iNum1 + iNum2) / 2; Println (dAvg); Return DAVG; // end avgTwoNumbers (int, int)} public static inte multiTwoNumbers (int iNum1, int iNum2) {int iMulti; // INum1 and iNum2 iMulti = iNum1 * keeps the product of iNum2; Println (iMulti); Return iMulti; // and multi-to-dos (int, int)} public static intensity two ennobox (int INM1, int INNM2) {int IDIv; // iNum1 and iNum2 catches the quotient of iDiv = INum1 / iNum2; Println (iDiv); Return IDI; // End divTwoNumbers (int, int)}
Proj2.java:78: error: symbol can not be found avgTwoNumbers (iNum1, iNum2); ^ symbol: variable INUM1 Location: class Proj2 Proj2.java:78: Error: The symbol can not be found AvgTwoNumbers (iNum1, iNum2); ^
menu
public static zero main (string [] args) {scanner KB = new scanner (System.in); // Keyboard int icon Allows input from; // System.out.print ("\ N \ nPress ENTER to continue"); kb.nextLine (); int iNum1; // user input to number 1 int INum2 ; // Keeps user input, number 2 catches user input for the system. Out.print ("\ nPlease complete the integer:"); INum1 = kb.nextInt (); System.out.print ("\ nPlease enter another integer:"); INum2 = kb.nextInt (); Iainmen = Menu (iNum1, iNum2); // call menu method} public static int menu (int INum1, Int iNum2) {/ * rest of the menu code /}
Comments
Post a Comment