~ Forums ~ Chat ~ And More ~

This Revolutionika Will Not Be Televised

Please take the time to join!

~ Feel Free to Post ~ No Account Needed ~

  • Post new topic
  • Reply to topic

Help Please!

Share

NO_tacoforme

Male Number of posts: 108
Age: 81
Location: Alaska
Points: 146
Reputation: 0
Registration date: 2008-08-12

Help Please!

Post by NO_tacoforme on Fri Sep 04, 2009 12:32 am

K so I just started a comp sci class, and instead of trying to fix it myself, I'm going to ask you to! here the code:

import java.util.Random;

import java.util.Scanner;

public class MinMaxRandom {

public static void main (String [] args) {

Random randomnumber = new Random();//Use randomnumber to call the Random generator

Scanner source = new Scanner (System.in);//Use the name source in all scanner objects

int min;//the user inputted minimum
min = 0;

int max;//the user inputted maximum
max = 0;

int num1;//the final total
num1 = 0;

int total;//the number to input as the range of the random number
total= max - min + 1;

System.out.println ("This program is going to display a random number");

System.out.println ("between the numbers of your choosing");

System.out.println ("Please input the minimum number(Positive Please!)");
min = source.nextInt();

System.out.println ("Please input the maximum number");
max = source.nextInt();

num1 = randomnumber.nextInt( total ) + min +1;

System.out.println ( num1 );

}

}

the problem is the number at the end is ALWAYS one higher than the value for the minimum variable.


_________________
I can has sig???????????
I can has taco!!!!!!!!!!!!
  • Post new topic
  • Reply to topic

Current date/time is Sun Aug 01, 2010 6:02 am