• pg7
  • NEWBIE
  • 0 Points
  • Member since 2009

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 2
    Replies

hi,all

 

 

now I'm developing calculation application.

while I'm developing my application, I wonder how to write array.

 

I want to use two random numbers by using array, so I write a code like this below.

 

 

 

     public Integer getRandomNumber1() {
    
          List<Integer> random = new Integer[2];
                   
          random.set(0, Math.round(Math.random()*100));

          random.set(1, Math.round(Math.random()*100));

 

          return random.get(0);

          return random.get(1);

 

     }
 

 

I need to return two random numbers in  getRandomNumber1 class.

 

Then I display two random numbers in a visualforce page.

 

 

I appreciate any advice.

 

thanks

  • November 08, 2009
  • Like
  • 0

hi all

 

 

i have a question.

 

now i develop a calculating application by using visualforce.

 

in a page, i get two random numbers, click "add" button and then add them in a next page.

 

but i can't keep random numbers in a next page.

 

how can i keep random numbers in a next page?

 

 

now this is code.

 

「add page(visualforce)」

<apex:page Controller="MathController">
    
          {!RandomNumber1} + {!RandomNumber2} = <br/>

          <apex:form >
               <apex:commandButton value="answer" action="{!Answer}" />
          </apex:form>
                    
</apex:page>

 

「MathController」

public class MathController {

     public double getRandomNumber1() {

          double ran1 = Math.round(Math.random()*100);
         
          return ran1;
           
     }
    
     public double getRandomNumber2() {

          double ran2 = Math.round(Math.random()*100);
         
          return ran2;
           
     }
 
     public PageReference Answer() {
    
          PageReference secondPage = Page.answer;
    
          secondPage.setRedirect(true);
    
          return secondPage;
    
     }
    
     public double getAddNumber() {

 

    //this AddNumber method has not been completed.

 

          double ans = ran1 + ran2;

 

          return ans;

 

     }

}

 

 

「answer page(visualforce)」

<apex:page Controller="MathController">
    
     The answer is {!AddNumber}.<br/>
    
</apex:page>

  • October 30, 2009
  • Like
  • 0

hi

 

 

i'm developing a calculation application.

 

i hope to get  a random number

and display it in a visualforce page by using an apex controller or some class.

 

 

could anybody tell me a code to get a random number?

  • October 29, 2009
  • Like
  • 0

hi all

 

 

i have a question.

 

now i develop a calculating application by using visualforce.

 

in a page, i get two random numbers, click "add" button and then add them in a next page.

 

but i can't keep random numbers in a next page.

 

how can i keep random numbers in a next page?

 

 

now this is code.

 

「add page(visualforce)」

<apex:page Controller="MathController">
    
          {!RandomNumber1} + {!RandomNumber2} = <br/>

          <apex:form >
               <apex:commandButton value="answer" action="{!Answer}" />
          </apex:form>
                    
</apex:page>

 

「MathController」

public class MathController {

     public double getRandomNumber1() {

          double ran1 = Math.round(Math.random()*100);
         
          return ran1;
           
     }
    
     public double getRandomNumber2() {

          double ran2 = Math.round(Math.random()*100);
         
          return ran2;
           
     }
 
     public PageReference Answer() {
    
          PageReference secondPage = Page.answer;
    
          secondPage.setRedirect(true);
    
          return secondPage;
    
     }
    
     public double getAddNumber() {

 

    //this AddNumber method has not been completed.

 

          double ans = ran1 + ran2;

 

          return ans;

 

     }

}

 

 

「answer page(visualforce)」

<apex:page Controller="MathController">
    
     The answer is {!AddNumber}.<br/>
    
</apex:page>

  • October 30, 2009
  • Like
  • 0

hi

 

 

i'm developing a calculation application.

 

i hope to get  a random number

and display it in a visualforce page by using an apex controller or some class.

 

 

could anybody tell me a code to get a random number?

  • October 29, 2009
  • Like
  • 0