Having trouble passing values between methods

So if this isnt the right spot for this.
Anyhow any coments on where I went wrong or need to fix will be apriciated.
So I got two methods that return a value (getHour() and getMinute(). The values that are returned I am tring to pass into showTime. However it doesn't seem to work as all I get is zero's.
I've done a search around on the net and Im starting to thing my intellagnce is limited.
import java.util.Scanner;
public class First
static int sH, sM;
    public static void main(String args[]){
        getHour();
        getMinute();
       showTime(sH,sM);
    static int getHour(){
        Scanner input = new Scanner(System.in);
        System.out.println("Please enter the hour: ");
        int setHour = input.nextInt();
        if(setHour <= 24){
            System.out.println("You entered " +setHour+ " for the hour.");
        }else{
            System.out.println("Please enter the hour number from 0 to 24");
            getHour();
     return sH;
     static int getMinute(){
        Scanner input = new Scanner(System.in);
        System.out.println("Please enter the minutes: ");
        int setMinute = input.nextInt();
        if(setMinute <= 60){
            System.out.println("You entered " +setMinute+ " for the minutes.");
        }else{
            System.out.println("Please enter the hour number from 0 to 60");
            getMinute();
        return sM;
    private static void showTime(int sH, int sM){
          System.out.println(+sH+":"+sM);
}

Hi,pls compare ur coding with the one i have posted below. In your code, the variables sH and sM are still in initialised state(value =0) and its not assigned with the values returned by getHour and getMinute methods. This is why the shoTime method returned zero. Hope i helped you.
import java.util.Scanner;
* @author Jaison KS-IT
public class First {
static int sH, sM;
public static void main(String args[])
getHour();
getMinute();
showTime(sH,sM);
static int getHour(){
Scanner input = new Scanner(System.in);
System.out.println("Please enter the hour: ");
int setHour = input.nextInt();
if(setHour <= 24){
System.out.println("You entered " setHour " for the hour.");
sH = setHour;
}else{
System.out.println("Please enter the hour number from 0 to 24");
getHour();
return sH;
static int getMinute(){
Scanner input = new Scanner(System.in);
System.out.println("Please enter the minutes: ");
int setMinute = input.nextInt();
if(setMinute <= 60){
System.out.println("You entered " setMinute " for the minutes.");
sM = setMinute;
}else{
System.out.println("Please enter the hour number from 0 to 60");
getMinute();
return sM;
private static void showTime(int sH, int sM){
          System.out.println(+sH+":"+sM);
}

Similar Messages

  • Passing values between methods in the same class

    Hi,
    How to pass internal tables or values between methods in the same class.
    How to check if the internal method in another method is initial or not.
    How to see if the method has already been executed.
    Thanks.

    Just declare the internal table as an attribute in the class - that way every method in this class has access to it.
    Since any method has access to all class attributes you can easily check if the internal table is initial or not.
    I am not aware of any standard functionality if a method has already been executed or not, one way would be to declare a class attribute for each method and set it once the method has been executed. That way every method in that class would know which method has already been executed or not.
    Hope that helps,
    Michael

  • Having trouble passing a getter method in a PreparedStatement

    Basically I've got it so that the user fills in their name, dob etc and when they click on register it inserts their information in a registrations table. However, I'm having trouble getting this working (NullPointerException) so any help would be greatly appreciated :)
    RegisterDetails.java
    public void writeToTbl() throws SQLException, ClassNotFoundException {
              DBase d = new DBase();
              GUI g = new GUI();
              i = 0;
              String regStr = "INSERT INTO REGISTRATION VALUES(?,?,?,?,?,?,?,?)";
              PreparedStatement st = d.getConnection().prepareStatement(regStr);          
              st.setInt(1, i);
              st.setString(2, g.getName()); //Exception error points to this line
              st.setString(3, g.getDOB());
              st.setString(4, g.getRoad());
              st.setString(5, g.getCity());
              st.setString(6, g.getCounty());
              st.setString(7, g.getPhone());
              st.setString(8, g.getEmail());
              st.executeUpdate();
         }GUI.java
    btnReg.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent ev) {               
                        if (ev.getSource() == btnReg && (agree.isSelected())) {
                             writeToFile(f, bWriter);
                             RegisterDetails reg = new RegisterDetails();
                             try {
                                  reg.writeToTbl(); //Exception error points to this line
                             } catch (SQLException e) {
                                  e.printStackTrace();
                             } catch (ClassNotFoundException e) {
                                  e.printStackTrace();
                        else {
    // JTextFields return their results
    public String getName() {
              return name.getText(); //Exception error points to this line
         public String getDOB() {
              return dob.getText();
         public String getRoad() {
              return road.getText();
         public String getCity() {
              return city.getText();
         public String getCounty() {
              return county.getText();
         public String getPhone() {
              return phoneNo.getText();
         public String getEmail() {
              return email.getText();So essentially I'm trying to get the information from the textfields and insert it into the registrations table but nothing seems to work. I've followed numerous tutorials on how to do it, but all of them use "fixed" values e.g., setString(1, "James") etc but I need the value of the JTextFields as they will be different every time. I'm completely at a loss with this at the moment so any help would be magnificent. :-)
    Thank you!

    so any help would be magnificent.Write a class that accepts the values that you want to insert. I would suggest passing an ArrayList. It opens the connection, does the insert, closes the statement and the connection.
    It does NOT have any GUI code in it.
    You then debug that class and verify it works.
    THEN, after you have verified it works, you write ANOTHER class that does the gui. It uses the class above to do the database work.

  • Having troubles passing values of Shuttle control to SQL Query of Report and Chart Region

    Hello,
    I am very new to APEX and need help for one of the Pa.I have a shuttle control on my page which populates Categories. Once user selects Categories from this control, I wish to pass the values to following SQL query :
    select * from emp_class where category IN ( LIST of VALUES FROM RIGHT SIDE SHUTTLE).
    I tried various ways of doing this including writing a java scripts which reads shuttle value, converts it into below string
    'Category1',Category2',Category3'. Then I set this value to a text box. And then I was expecting that below trcik would work
    select * from emp_class where category IN (:TXT_VALUES)
    I am sure this is not right way and hence its not working. Can you please guide me here with options?
    Many Thanks,
    Tush

    b96402b4-56f7-44ba-8952-fb82a61eeb2c wrote:
    Please update your forum profile with a real handle instead of "b96402b4-56f7-44ba-8952-fb82a61eeb2c".
    I am very new to APEX and need help for one of the Pa.
    Don't understand what this means. What is "Pa"?
    select * from emp_class where category IN (:TXT_VALUES)
    I am sure this is not right way and hence its not working. Can you please guide me here with options?
    This is a common fallacy. In
    select * from table where columnvalue in (7788, 7839, 7876)
    (7788, 7839, 7876) is an expression list and the predicate is evaluated as a membership condition.
    In
    select * from table where columnvalue in :P1_X
    :P1_X is a scalar string, incapable of containing multiple values.
    In an APEX standard report, a PL/SQL function body returning an SQL query report source with lexical substitution can be used to produce a "varying IN-list":
    return 'select * from table where columnvalue in (' || :P1_X || ')';
    where P1_X contains fewer than 1000 values, has been sanitized for SQL injection, and string values are properly quoted.
    Some people suggest the following approach, which will also work in APEX interactive reports:
    select * from table where instr(':' || :P1_X || ':', ':' || columnvalue || ':') > 0
    However this is non-performant as it eliminates the possibility of the optimizer using indexes or partition pruning in the execution plan.
    See varying elements in IN list on Ask Tom, and emulating string-to-table functionality using sql for efficient solutions.

  • How to pass values between views in FPM - GAF

    Hi Experts ,
    i have a doubt in FPM how to pass values between views .
    For Example:  i am having 2 views -  1 ) overview , 2 ) edit  using  the GAF
    in 1st view (overview ) i have a table displaying the employee details , i will select a single employee from that table for editing .
    how to pass the selected employee details to the 2 nd view (edit ) .
    Thanks & regards
    chinnaiya P

    Hi chinnaiya pandiyan,
    Please follow below steps:
    1. To achieve this u need to create two context nodes in the component controller.
    2. Say one is EMPLOYEE_DATA and other is SELECTED_DATA.
    3. Set the Cardinality of EMPLOYEE_DATA to 0..n and SELECTED_DATA to 1..1.
    4. Add same attributes to both nodes. (probably all those fields that are required in table and/or in edit view.
    5. Map both these nodes to OVERVIEW view.
    6. Map only SELECTED_DATA node to EDIT view.
    7. Create table in OVERVIEW view based on EMPLOYEE_DATA node.
    8. Create edit form in EDIT view based on SELECTED_DATA node.
    9. While navigating from OVERVIEW view to EDIT view, read the selected element of EMPLOYEE_DATA node and copy it to an element of SELECTED_DATA node. This should be written in PROCESS_EVENT method of component controller inherited from FPM component.
    10. Now u got the selected data in SELECTED_DATA node which will be displayed in EDIT view.
    Regards,
    Vikrant

  • Passing Parameter between Methods

    I have some problems because i don't really know how to pass parameter between methods in a java class.
    How can i do that? below is the code that i did.
    I want to pass in the parameter from a method called dbTest where this method will run StringTokenizer to capture the input from a text file then it will run storeData method whereby later it will then store into the database.
    How can i pass data between this two methods whereby i want to read from text file then take the value to be passed into the database to be stored?
    Thanks alot
    package com;
    import java.io.*;
    import java.util.*;
    import com.db4o.ObjectContainer;
    import com.db4o.Db4o;
    import com.db4o.ObjectSet;
      class TokenTest {
           private final static String filename = "C:\\TokenTest.yap";
           public String fname;
         public static void main (String[] args) {
              new File(filename).delete();
              ObjectContainer db=Db4o.openFile(filename);
         try {
            String fname;
            String lname;
            String city;
            String state;
             dbStore();
            storeData();
         finally {
              db.close();
         public String dbTest() {
            DataInputStream dis = null;
            String dbRecord = null;
            try {
               File f = new File("c:\\abc.txt");
               FileReader fis = new FileReader(f);
               BufferedReader bis = new BufferedReader(fis);
               // read the first record of the database
             while ( (dbRecord = bis.readLine()) != null) {
                  StringTokenizer st = new StringTokenizer(dbRecord, "|");
                  String fname = st.nextToken();
                  String lname = st.nextToken();
                  String city  = st.nextToken();
                  String state = st.nextToken();
                  System.out.println("First Name:  " + fname);
                  System.out.println("Last Name:   " + lname);
                  System.out.println("City:        " + city);
                  System.out.println("State:       " + state + "\n");
            } catch (IOException e) {
               // catch io errors from FileInputStream or readLine()
               System.out.println("Uh oh, got an IOException error: " + e.getMessage());
            } finally {
               // if the file opened okay, make sure we close it
               if (dis != null) {
                  try {
                     dis.close();
                  } catch (IOException ioe) {
                     System.out.println("IOException error trying to close the file: " +
                                        ioe.getMessage());
               } // end if
            } // end finally
            return fname;
         } // end dbTest
         public void storeData ()
              new File(filename).delete();
              ObjectContainer db = Db4o.openFile(filename);
              //Add data to the database
              TokenTest tk = new TokenTest();
              String fNme = tk.dbTest();
              db.set(tk);
        //     try {
                  //open database file - database represented by ObjectContainer
        //          File filename = new File("c:\\abc.yap");
        //          ObjectContainer object = new ObjectContainer();
        //          while ((dbRecord = bis.readLine() !=null))
        //          db.set(fname);
        //          db.set(lname);
        //          db.set(city);
            //          db.set(state);
    } // end class
         Message was edited by:
    erickh

    In a nutshell, you don't "pass" parameters. You simply call methods with whatever parameters they take. So, methods can call methods, which can call other methods, using the parameters in question. Hope that makes sense.

  • Passing values between event structure cases

    Hello everybody,
    I have a question concerning the event structure  - how to pass values (let's say a string / the state of a boolean control / the value of a numeric control value / an array of numeric values) between event cases ?
    There seem to be 2 situations here  :
    - when you need to pass the value of the control that triggers an event;
    - when you need to pass the value of a control which is modified in an event case.
    I have read the documentation but i still do not understand very clearly how to do this. Maybe you can point me in the right direction (maybe some threads on the forum that i have missed).
    Thank you very much !!
    (KUDOS for everyone who is interested in this )

    AndreiN2014 wrote:
    - when you need to pass the value of the control that triggers an event;
    - when you need to pass the value of a control which is modified in an event case.
    The first question isn't worded very well.  What exactly are you looking to do?  Are you looking for an event that specifically relates to that control?  If so, just drop it inside of the event and wire it.  Are you looking to trigger multiple events from the same control?  Ie, you hit the control, event1 is triggered which then triggers event2 ... ?  If so, you might consider taking a look at a different architecture.  I can think of very few cases where I'd prefer do this over something like having the button trigger a state and using the state machine architecture. 
    Others have pointed out the Shift Register.  This is the typical way to pass values between one iteration of a loop to another.  We can assume you have some sort of loop outside of the event structure to make it run a second time.  Put a shift register on this loop and the value wired into it will pass each iteration.  But, if it's just a random control, you can also just leave that outside of the event structure and wire it in as well.  This will provide the new value to the next occurrence of the event structure.
    You really need to define your problem before trying to solve it.

  • Use context to pass value between JPF and Java Control

    hi,
    Can we use context to pass value between JPF and Java Control? It works if i m using InitialContext in the same machine but i dun think it will works if i put Web server and application server in different machine. Anyone have an idea how to do it?
    I also want to get the method name in the onAcquire callback method. Anyone knows how to do this?
    thks
    ?:|

    Hi.
    Yoy can the next options for make this:
    1. Pass your values in http request.
    example: http://localhost/index.jsp?var1=value1&var2=value2&var3....
    2. You can use a no visible frame (of height or width 0) and keep your variables and values there using Javascript, but of this form, single you will be able to check the values in the part client, not in the server. Of this form, the values of vars are not visible from the user in the navigation bar.
    Greeting.

  • Passing values between jsp and php

    hi there, is it possible to pass values between jsp and
    php? i really need to find out the way if there is
    any. thanks in advance
    -azali-

    Yes, there are a few ways to do this.
    1) Think about using Cookies.
    2) Maybe use a Redirect passing the values in the Query string.
    3) Retain the data in a repository in the back end.
    4) Using Hidden fields within your pages.
    I am sure you can use these Idea's for a base to develop other methods on how to pass values back and forth from JSP -> PHP and vice versa.
    -Richard Burton

  • How to Pass values between one webdynpro application to another

    Hi ,
        I know How to Pass Values Between the Application by URL But For My Requirement NO need The Pass in URL Rather Than That Please any one TEll me How to GEt VAlues BEtween the application......
    Thanks
    ANANTH.

    If you dont want to pass values through URL, then you must have to use component Usage with interface node.
    Or you can try like this,
    by appending field value to url,
    Data w_url type string,
    w_value type string.
    get the url of calling aplication
    call method cl_Wd_utilities->construct_wd_url
    exporting application name = name of second application( to which u want to pass parameter )
    importing out_absolute_url = w_url.
    ***Make the value type compatible that has to passed with url.
    w_string = lv_pernr
    ***Now attach the parameter and its value with url that have to passed to 2nd application
    call method cl_http_Server=>append_field_url
    exporting name = 'pernr'
    value = ' w_value'
    changing url = w_url.
    then popup window for 2nd application with above url
    lo_window = lo_window_manager->create_external_application ( url = w_url ).
    lo_window -> open( ).
    ***now in wddoinit of 2nd application
    data lv_param type string
    lv_param = wdr_task=>client_window->get_parameter( ' pernr ').
    Now you can use lv_param in 2nd application.
    Regards
    srinivas

  • Pass values between pages

    Hello experts!
    I am trying to pass value between two pages without page submit.
    I set item value from first page to session state by dynamic action. Then I am trying to pass this value to second page, I use button which redirects to second page and sets item value on second page with value from first page.
    But approach this does not woks as I expected. The value from the first page is not passed to the second page when I click on button. Value is passed to the second page only if I:
    1. set some value to item on first page (e.g. XX);
    2. click on button which redirects to the second page;
    3. get back to first page;
    4. set some new value to the item (e.g. YY);
    5. click on button;
    6. then the first value from session state is passed to sthe econd page (value XX)
    Could anybody tell me where I make a mistake, or what is wrong in my solution?
    Test appl.
    www.apex.oracle.com
    http://apex.oracle.com/pls/apex/f?p=9027:LOGIN_DESKTOP:6946284921064
    workspace: kurintest
    username: [email protected]
    passwd: kurintest
    appl: 9027 pass_value
    Thanks in advance!
    Jiri

    Jiri N. wrote:
    Hello experts!
    I am trying to pass value between two pages without page submit.
    I set item value from first page to session state by dynamic action. Then I am trying to pass this value to second page, I use button which redirects to second page and sets item value on second page with value from first page.
    But approach this does not woks as I expected. The value from the first page is not passed to the second page when I click on button. Value is passed to the second page only if I:
    1. set some value to item on first page (e.g. XX);
    2. click on button which redirects to the second page;
    3. get back to first page;
    4. set some new value to the item (e.g. YY);
    5. click on button;
    6. then the first value from session state is passed to sthe econd page (value XX)
    Could anybody tell me where I make a mistake, or what is wrong in my solution?A redirect button and it's target URL&mdash;including items to be set and their values&mdash;are rendered on page show, in this case before <tt>P2_ITEM1</tt> has a value. Look at the page source when the page is first rendered:
    <input type="button" value="Button1"onclick="apex.navigation.redirect(&#x27;f?p=9027:3:11397156385140::NO:RP,3:P3_ITEM1:&#x27;);" id="P2_BUTTON1"  />No value substituted for <tt>&P2_ITEM1.</tt> in the URL.
    Why do you want to navigate between these pages without a page submit? As APEX has to render page 3 anyway, why not submit and branch?

  • Pass Values between two Function Modules RFC in Portal

    I need to pass values ​​between 2 FM RFC.
    I have an implicit enhancement in HRMSS_RFC_EP_READ_GENERALDATA RFC function module.
    PERNR LIKE  PSKEY-PERNR
    ENHANCEMENT 1  Z_ESS_EXPORT_PERNR.    "active version
      EXPORT pernr to memory id 'PMK'.
      set parameter id 'PMK' field pernr.
    ENDENHANCEMENT.
    On the other hand an RFC function module that has the code:
            pmk    LIKE PSKEY-PERNR,
            pmk_2  LIKE PSKEY-PERNR.
      get parameter id 'PMK' field pmk.
      IMPORT pmk_2 FROM MEMORY ID 'PMK'.
    When the execution is done in development environment, the modules function at the level of R3, the "get parameter id" works only if the debbuger is classic, otherwise not work. The Import to memory id never works.
    In the environment of quality, r3 do not work any of the 2 sentences. If run from portal (which is as it should be) does not work.
    Thanks if anyone can help me get the problem. Both function modules are executed at the portal.
    Regards
    Edited by: Daynet1840 on Feb 15, 2012 2:02 AM

    When the execution is directly in r3, in development environment or quality, does the set / get parameter id. Export / Import memory id not work.
    But if the FM are called from the portal, does not the set / get parameter id.
    I tried changing the sentence as I indicated harishkumar.dy still not working.
    Madhu: They're in different function groups, one is standard and the other not.
    Regards
    Edited by: Daynet1840 on Feb 15, 2012 3:08 PM
    Edited by: Daynet1840 on Feb 15, 2012 3:11 PM

  • Pass values between panels in different UI files

    Hi All,
    Is there a way to pass values between panels belonging to User Interface files ? Or is it easier to have one .uir and different .c and .h files ?
    Thanks,
    Kanu

    I should say that it's not possible for you to trap events from the first popup,and this depends on the basic concept of "popup panel".
    When you install a popup panel, all user interaction with existing panels is excluded: all focus it aimed at the popup only, no other user interface event is generated. If you launch another popup from the first one, the second popup prevails over the first one and no event can be generated on the first panel until the second one is closed.
    Handling a chain of two popup panels while looping on GetUserEvent can lead to unpredictable situation not so easy to untangle.
    Proud to use LW/CVI from 3.1 on.
    My contributions to the Developer Zone Community
    If I have helped you, why not giving me a kudos?

  • Trouble passing values to subpanels

    I seem to be having issue pass values to my sub VIs in a subpanel.  I'm using the invoke node and control value set command.
    I am able to pass a database reference that I'm using, but when I try Boolean values, I get no response.  I'm also trying to use one of the Boolean values to fire an event.  The front panel of my sub VI looks as though the FP button is being pressed, but my value doesn't change and my event doesn't fire.
    I've reviewed as may forum threads as I could and have looked through the bug reports without any luck.  Any ideas?

    attached is the code snippet.   You can use this as a subVI in place of where you are setting the control value or just hammer the code in directly.  Add error handling as you see fit, although you should note that if you use the error handling within the for loop, you will probably get an error, probably better to move the 'to specific' outside the loop.
    Paul <--Always Learning!!!
    sense and simplicity.
    Browse my sample VIs?
    Attachments:
    setCtrlValSignal.vi ‏11 KB

  • Hi, ive been having trouble passing my logic sessions to another computer, we're both using a macbook pro 10.6.8 and logic pro 9 with the same plugins, the session opens in the other computer but all the synths reset to presets

    Hi, ive been having trouble passing my logic sessions to another computer, we're both using a macbook pro 10.6.8 and logic pro 9 with the same plugins (native instruments komplete 7), the session opens in the other computer but all the synths reset to presets, this didnt happen the first time I shared a session, but its been happening lately quite often

    kwmlr439 wrote:
    CSOUND Read the title please:
    Re: Macbook Pro 10.6.8 RAM Upgarde to 8 GB
    The amount of RAM is not dependant on the operating system. It is all about the model of you Mac.
    10.6.8 is the version of OS X that is installed on your system. It has no real baring on the amount of RAM that CAN be installed.
    Personally I have never had good luck with Corsair RAM. I have always had good luck with Crucial and Kingston.
    Message was edited by: Shootist007
    Message was edited by: Shootist007

Maybe you are looking for

  • How do I keep imported albums featuring various artists in one list?

    I'm new to iTunes and have not figured out how to create a single library listing when importing CD's that feature various artists. iTunes always creates separate library listings for each artist, spreading them across the library in alphabetical ord

  • Object not found in lookup of RequestResponseBean.

    hi all, i am doing the scenario file to rfc to file without BPM . I am facing the problem in my sender communication channel. that is Error: com.sap.engine.services.jndi.persistent.exceptions.NameNotFoundException: Object not found in lookup of Reque

  • Cant save as AI but can as PDF

    Using PC Windows XP Service Pack 3; CS5 Illustrator 15.1.0, 2gb Ram, 50gb Free HD space. Opening an AI file sent from Japan, not sure of its PC or MAC (is there a way to find out). All fonts are as outlines, images embedded. After making a few simple

  • JNI, invocation-API, JNI_CreateJavaVM

    Hi, I want to compile 'invoke.c' from the internet and get a compiler-error. Does anybody know, what to do? Thanks Ully c-code: #include "jni.h" jint res; JavaVM *jvm; JNIEnv *env; JDK1_1InitArgs vm_args; res=JNI_CreateJavaVM( &jvm, &env, &vm_args );

  • How change application´s state from a component´s function

    Hi, I´m doing an Flex application, I have created a component "usersRegister", that have next function: private function comprobacionBBDD():void{ if(numero>0){ mensaje="Perfect.\n\n\n Wellcome."; HERE I WANT CHANGE THE STATE }else if(numero==-1){ men