Symbianize Forum

Most of our features and services are available only to members, so we encourage you to login or register a new account. Registration is free, fast and simple. You only need to provide a valid email. Being a member you'll gain access to all member forums and features, post a message to ask question or provide answer, and share or find resources related to mobile phones, tablets, computers, game consoles, and multimedia.

All that and more, so what are you waiting for, click the register button and join us now! Ito ang website na ginawa ng pinoy para sa pinoy!

pa help po sa error ko

sleepsteal

Novice
Advanced Member
Messages
27
Reaction score
0
Points
26
Gumagawa po kase ako ng random number generator na may operations sa java. netbeans po gamit ko. eto po ung code:

package randomgenerator;

import java.util.Random;
import java.util.Scanner;


public class RandomGenerator {


public static void main(String[] args) {

Random rand = new Random();
Scanner answer = new Scanner(System.in);

int number1 = rand.nextInt(0)+1;
int number2 = rand.nextInt(9)+1;
int num = rand.nextInt(4)+1;
int userAnswer;
int result;
char operator;


for (int counter = 0; counter <=10; counter ++){

switch (num)
{
case 1: operator = '+';
break;
case 2: operator = '-';
break;
case 3: operator = '*';
break;
case 4: operator = '/';
break;

}

if (num == 1)
{
System.out.print(counter + ". " + number1 + "+" + number2 + "=" );
userAnswer = answer.nextInt();
result = number1 + number2;
if (userAnswer == result)
{
System.out.println("Correct!! \n");
}
else
{
System.out.println("Incorrect!! \n");
}


}

if (num == 2)
{
System.out.print(counter + ". " + number1 + "-" + number2 + "=" );
userAnswer = answer.nextInt();
result = number1 - number2;
if (userAnswer == result)
{
System.out.println("Correct!! \n");
}
else
{
System.out.println("Incorrect!! \n");
}


}

if (num == 3)
{
System.out.print(counter + ". " + number1 + "*" + number2 + "=" );
userAnswer = answer.nextInt();
result = number1 * number2;
if (userAnswer == result)
{
System.out.println("Correct!! \n");
}
else
{
System.out.println("Incorrect!! \n");
}


}

if (num == 4)
{
System.out.print(counter + ". " + number1 + "/" + number2 + "=" );
userAnswer = answer.nextInt();
result = number1 / number2;
if (userAnswer == result)
{
System.out.println("Correct!! \n");
}
else
{
System.out.println("Incorrect!! \n");
}


}
}

}

}

eto nmn po ung error:


run:
Exception in thread "main" java.lang.IllegalArgumentException: bound must be positive
at java.util.Random.nextInt(Random.java:388)
at randomgenerator.RandomGenerator.main(RandomGenerator.java:15)
C:\Users\User\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 0 seconds)

TIA mga sir
 
Back
Top Bottom