Using the return statement to return the value - Java Object Oriented Design

Java examples for Object Oriented Design:Method

Introduction

A program that uses a method that determines a random number between 1 and 10:

Demo Code

public class RandomNumber {
     public static void main(String[] args) {
           int number = getRandomNumber();
           System.out.println("The number is " + number);
     }//w ww .j  a v  a2s.  co  m

     public static int getRandomNumber() {
           int num = (int)(Math.random() * 10) + 1;
           return num;
     }
}

Related Tutorials