Random Number Generator Then Summing

Aug 29, 2014

I am brand new to programming and java. I decided I wanted to learn programming so now I'm in a class. I am into my second week and my assignment is to generate 100, 3 digit numbers then add them together. I understand how vast java is, but as of right now we have only studied if/else/switch statements, I was able to get the 100, 3 digit numbers generated, but I cannot add then together.

import java.util.Random;
import java.util.Math;
public class ThreeDigitGenerator {
public static void main(String[] args) {
int sum = 0;

[Code] ....

View Replies


ADVERTISEMENT

How To Create Simple Random Number Generator For Number Between 1 -10

May 18, 2015

I am working on a little nothing project, but I wanted to create a random number generator for a silly game where the user guesses the number.I have used google, but they are using LOG statements, what it does.

View Replies View Related

Random Number Generator Error

Dec 1, 2014

I am new at coding and I can't seem to figure out why my random number generator (numGen) won't let me compile. this is the game class to a game i'm making called Bagels. its very similar to the game mastermind in the sense that you have to try to guess a three digit number and the computer will return feedback giving you clues that will guess the number.

import java.util.*;
import java.io.*; 
public class BaglesGame {
public static numGen() {
Random Rainbow = new Random ();
firstDigit = "" + Rainbow.nexInt(10);
 
[Code] .....

View Replies View Related

Random Phone Number Generator

May 13, 2011

I am trying to make a phone number generator. I get the following error though when trying to compile.

my post

C:JAVA_PROGRAMMING_CODEcode1RandomPhoneNum>javac RandomPhoneNum.java
RandomPhoneNum.java:23: cannot find symbol
symbol : method toOctalString(int)
location: class RandomPhoneNum
strippedNum = toOctalString(num1);
^
1 error

Here is the code so far

import java.util.Random;
public class RandomPhoneNum
{
public static void main(String[] args)
{
System.out.println("This app prints out a random phone number.");

[Code] ....

Also, how did you people know about octal base numbers? I would never have known that. What I can do to improve my math ability?

View Replies View Related

Random Number Generator And Local Variables

Jul 31, 2014

Basically this code is supposed to create an int array of 50 elements, then pull the elements listed in positions 1-6 to make a lottery draw.

Problem is it gets down to that last "For" statement and then says "duplicate local variable i." If I attempt to separate it from the previous for loop with curly braces, then it gets mad and says it doesn't know what "local variable i" even IS. So I tried changing it to "j" in the last statement and it couldn't recognise that either. I feel like I need to change the variable name in that second for loop but I'm not sure how to make it understand that the second variable is going to be outputting the values from the first variable.

public class Lottery {
public static void main(String[] args) {
// TODO Auto-generated method stub
int []nums = new int [50];
for (int i = 1; i <50; i ++) {nums[i] = i;}

[Code] ....

View Replies View Related

Random Number Generator To Pick Index From Array?

Oct 31, 2014

Im creating my 2nd project ever and its a hangman game. I created an Array that has 20 different words in it and need to create a function that generates a random number to pick a random index of the array to obviously pick a random word. I cannot figure out the syntax for the life of me.

View Replies View Related

How To Write Random Number Generator That Will Not Contain Any Repeat Value In A Range

Apr 24, 2015

I am trying to write a Random Number Generator that will not contain any repeat value in a given range

something this I have try so far

import java.util.Random;
/**
* This class is used to generate a
* Range of Random Number in a range from int a to int b
*/
public class RandomNumberGenerator {
public static void main(String[] args) {
int[] arr=randomNummbers(1, 20);
for(int j=0;j<arr.length;j++){

[Code]...

although this code generate random numbers but some values are also getting duplicate.So how to write a program for random number that will not repeat any integer in range?

View Replies View Related

Random Number Generator To Pick Index From Array

Oct 31, 2014

I am creating my 2nd project ever and its a hangman game. I created an Array that has 20 different words in it and need to create a function that generates a random number to pick a random index of the array to obviously pick a random word.

View Replies View Related

Comparing Array Or Int To 4 Digit Number From Random Generator?

Apr 4, 2015

How do I compare an array (or maybe int?) (example: 3572) to a 4digit number from random generator? how many of the four digit match the generated numbers.

View Replies View Related

Quiz Game Program - Random Number Generator

Nov 18, 2014

I've run into some problems with my Quiz-game program. What I basicly want it to do is generate a random number that is tied to the other windows I have for the program (I want a new random question to be generated once I have guessed on the first one). I've read about a few different ways to approach this but everything I get is a pure number generator.

I imported

import java.util.Random;

into my program but I don't know where to go from there.

View Replies View Related

Random Phone Number Generator - Include Dashes In The Output

Apr 11, 2011

I've been working on a personal project again in Unit 3 of my text book and this time they want me to make a random phone number generator. Here's the actual directions:

"Write an application that creates and prints a random phone number of the form XXX-XXX-XXXX.

Include the dashes in the output.

Do not let the first three digits contain an 8 or 9 (but don't be more restrictive than that), and make sure that the second set of three digits is not greater than 742.

Think through the easiest way to construct the phone number. Each digit does not have to be determined separately."

With this assignment I came across 2 problems:

1. What I tried was that since the first 3 numbers have to be a random number with no 8's or 9's I tried doing this algorithm:

int first0, first1, first2, second, third, random0;
first0 = generator.nextInt (999);
random0 = generator.nextInt (8);
first1 = first0.replace('8', random0);
first2 = first1.replace('9' random0);

The problem is that Java won't allow me to generate random numbers this way. Are there any easier ways of generating numbers that doesn't contain specific number (such as 8 or 9 in this case?)

2. I was thinking about this throughout the whole project and what if I generate a number such as 27 (less than 3 or 4 digit number) rather than 3 or 4 digit numbers? How would it show 0027 or 027 instead of 27 for the phone numbers?

import java.util.Random;
public class pp0303 {
public static void main (String[] args){
Random generator = new Random();
int first0, first1, first2, second, third, random0;

[Code] ....

RESULTS:

Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Cannot invoke replace(char, int) on the primitive type int
Cannot invoke replace(char) on the primitive type int
Syntax error on token "random0", delete this token
at pp0303.main(pp0303.java:15)

View Replies View Related

Unable To Make Gradebook That Uses Random Number Generator To Give Score

Nov 7, 2014

I`m trying to make a gradebook that uses random number generator to give the score, I also need to implement student numbers and sort everything with a total at the bottom. But I cant figure out how the bubblesorting works. This is my code so far:

package karakterbok;
import static java.lang.Math;
import java.util.Random;
public class Karakterbok {
public static void main(String[] args) {
Random karakterer = new Random();
Random studid = new Random ();

[Code]...

how to sort this using bubblesort?

View Replies View Related

Images Of Cards - Shuffle Deck With Random Number Generator And Display First 10

Aug 18, 2014

So I'm trying to make an applet that displays images of cards. The applet has a deck of 52 playing card images. It should shuffle the deck with a random number generator and display the first 10 cards of the shuffled deck.

With this code I have about 100 errors and I'm not sure what I'm doing wrong: I know I have to use arrays in order to ultimately display the images, but do I have to create Image objects for the Image [] cards array? I am getting many "class, interface, enum expected" errors as well as others.

import java.util.Random;
import java.awt.Image;
import java.applet.Applet;
import java.awt.Graphics;
public class unit12 extends Applet
{

[Code] .....

View Replies View Related

Tic Tac Toe Game - Random Number Generator And Two Dimensional Arrays For Game Board

May 9, 2015

Im trying to make a tic tac toe game that you play against the computer using a random number generator and two dimensional arrays for the game board. Im not trying to make a GUI, the assignment is to have the board in the console, which I have done. I have run into a few problems with trying to get the computer player to correctly generate 2 integers and have those two integers be a place on the game board. Here is my code so far.

import java.util.Random;
import java.util.Scanner;
 public class TicTacToe {
 private static Scanner keyboard = new Scanner(System.in);
private static char[][] board = new char[3][3];
public static int row, col;
 
[Code] ....

View Replies View Related

Random Generator And 2D Arrays?

Sep 21, 2014

So im making this ghost game where i display an 8x8 filled with 0s and a randomly generator five 1s in there I can get it to display 0s and add 1s, however sometimes the 1s that are randomly generated sometimes go on the same spot making it look like there are only four 1s. How would i go about fixing that?

package Grade12;
 import java.util.Random;
 public class Ghost {
 public static void main(String[] args) {
 Random generator = new Random();
 int gameboard [][] = new int [8][8];
int randomx, randomy, counter = 0, sum = 0; 
for(int row = 0; row < 8; row++){
for(int col = 0; col < 8; col++){ 
(gameboard[row][col]) = 0;
 }

[code]...

View Replies View Related

Random Card Generator

Mar 16, 2015

I've been trying to get a card generator working, but hells bells nothing is easy in java (unless you already the correct answer) trying to figure out the correct way to apply a method you don't understand is like being asked for the German word for banana in Spanish class.

import java.util.Random;
import java.util.Scanner;
class jacktest
{
public static void main ( String[] args ) {
Random r = new Random();

[code]....

my next step might be using object (hammer >=computer)=watch telly instead.

View Replies View Related

Random File Name Generator

Nov 30, 2014

I am splitting a zip file and want to name each fragment with a random name. I want to use java coding for generating this random file name.

View Replies View Related

Creating Random Password Generator?

May 8, 2014

Keeping the passwords at 7 charactersHiding the "[object HTMLInputElement]" next to the passwordsMaking the "Clear" button work to clear the forum

<!DOCTYPE html>
<!-- passwordgenerator.html -->
<html lang="en">

[Code]....

View Replies View Related

Random Bingo Card Generator

May 26, 2014

I'm trying to create a program that will be able to generate random Bingo cards. This is what I have so far.

Java Code:

import java.util.Random;
public class BingoCard
{
private int[][] card;

public BingoCard(Random random)
{
card = new int[5][5];
for (int c = 0; c < 5; c++)

[code]...

The problem with this program is that even with the checkForDuplicateValues method, which checks for duplicate values of a column and replaces the values, it still prints out bingo cards with duplicate values!

View Replies View Related

Program Is A Random String Generator

Sep 11, 2014

The program is a Random String Generator; it takes user input (type of string, and length), and then generates a string with their requested method. Its extremly simplistic, but had some interesting coding challenges considering I only just did 'Hello World' a few days back xP I actually already have quite a few additions and modifications I want to make to it, but wanted to get a bit of feedback on it otherwise.

The Main Class, RandomStringGenerator.java:URL...
InputHandler.java:URL....
RandomGenerator.java: URL....

View Replies View Related

Random 4 Char Generator Generates 3 Numbers Instead?

Jul 10, 2014

I'm trying to make the basis of a complex (pseudo)random password generator, but instead of 4 chars it is printing a 3 digit number.

public class PasswordGen {
public static void main (String[] args) {
char[] alphabet = "abcdefghijklmnopqrstuvwxyz".toCharArray();
int w = (int) ((Math.random() * 25 +1)); // pick a letter of the alphabet

[Code] ....

View Replies View Related

Random Generator Method Is Not Giving Correct Average?

Aug 4, 2014

Create an array that will store 7 temperatures.

Populate the array with 7 random temperatures from 1 to 100 degrees. (hint use a for loop and a Random number Generator)After the temperatures are in the array, calculate the average of the temperatures in the array.

Print out the average.Print out each temperature in a statement comparing it to the average such as:

The average temperature is 48.94

Temperature 1 is 5.0 and is below average.

Temperature 2 is 67.8 and is above average.

import java.util.Random; 
public class ArrayOfTemperatures
{
public static void main(String[] args) {
// Declare an array
int[] randomtemps = new int[7];
temps[0] = 45;

[code]....

View Replies View Related

Java Random Road Cross - Generate Random Number Between One To Ten

Dec 8, 2014

The program I'm supposed to create generates a random number between one to ten. Then the program is to ask me if I wish to cross the road. If you choose to cross, the outcomes for 0-2 are "You crossed safely." For 3-5, 75% of the time it should say "RIP you got run over", and 35% of the time it should say "You crossed the street." For 6-8, 60% of the time it should say you made it.", and 40% of the time it should say "You died". For 9-10, it should say "RIP".

So far I have gotten the random number generation part working. I have up to here:

import java.util.Random;
public class test4 {
public static void main(String[] args) {
Random random = new Random();
for(int i =0; i < 1; i++){
int num = random.nextInt(10) + 1;
System.out.println("The number of cars on the street are: " + num + "Do you wish to cross the road?");
}
}
}

View Replies View Related

Prime Number Generator - Range From 0 To 199

Feb 5, 2015

public class printprimes2{
 public static void main(String[] args){
  for( int i = 1 ; i <=199 ; i++ ) //iterate 1 - 199; 2 is prime {
for ( int j = 2 ; j < i ; j++ ) //iterate 2 - potential composite EXCLUSIVELY; every number can be divided by one and itself

[Code] ....

It doesn't print only prime numbers but all numbers that range from 0 to 199. What do you think I am doing wrong?

View Replies View Related

Arrays And Number Generator - Determine And Print Largest And Smallest Values

Dec 4, 2014

/*
Purpose: To write the methods and the rest program. The program should fill a 4 X 4 2 dimensional array with random numbers between 100 and 200. The program should then determine and print the largest and smallest values within the array using two Methods Largest and Smallest. The program should then determine and print the number of values within the array that are even using a function called Even. The program should also enter a loop that will only terminate when the user inputs a -1 as a choice. The loop should continue to ask the user to guess a number that was randomly generated. The program should call the Findit function to determine if the number was in the array. The program should print out the values in the array when the user selects a -1 and then terminate.
*/

import java.util.Scanner;
import java.util.Random;
public class LNFI_2DArray
{
public static void main(String[] args) {
int guess;
int[] array = new int[4];

[Code] ....

I just had this code working, then all of a sudden i was hit with a 'keyboard leak' error code.

View Replies View Related

Random Number Calculator

Feb 1, 2015

the program basically has a random number generating, and I want to ask the user to try to guess the number, and keep guessing until the number is right. In addition to this, I need to put in extra conditions for too high or too low by 10. So for example, if they user guesses a number and its off by more than 10, then it prints that they guessed too high, and if its below 10 they guessed too low.

import java.util.*;
public class RandomNum
{
public static void main(String[] args)
{

Scanner scan = new Scanner(System.in);

[code].....

Modify the program to keep the user trying to guess the number till he/she gets it right, and stop once you guess the right number.Too high, high, too low, too low( If it's off by more than 10 = way too high, if its less than 10, way too low)

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved