The problem you have is that it doesn't produce a 4x4 array. For that you need more nested for loops.This is what I have tried so far:
import java.util.Scanner;
import java.util.Random;
public class challenged2e
{
static Scanner console = new Scanner(System.in);
public static int i=0;
public static void main (String args[])
[code]...
I get 21 errors and they all have to do with i and j.
I want to do a Registration page on some website. i connected to mysql and creating some id like 1 and 2 like this , but i don't want like this. i want to generate v21001 and v21002 to generate on every registration.
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;
I am writing a payroll program .The program generates random PPS numbers and then takes in users information and calculates the salary accordingly. I am using netbeans and my code is showing errors on line 18 and 42 ("cannot find symbol")on the code for grossPay(). The program seems to crash after a new PPS number is generated and will not run.
package sd_assg_2; import java.util.Arrays; import java.util.Random; import javax.swing.JOptionPane; public class SD_ASSG_2 { public static void main(String[] args) { String[] newPPs = getPPSno();
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?"); } } }
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; }
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.
//read the file //make the numbers 1 string line //count the number of repetitiveness in the string for the numbers //display four lowest ones
import java.io.*; import java.util.*; public class Lottery2
[Code] ....
when I run it the array gets sorted but how do i keep the data in other words
what it is supposed to do is grab numbers from a file, and give me the lowest 4 numbers back. I know the numbers using the array but how do i pull out the lowest 4 and keep the data true no matter what numbers or how many of them are in the file.
I'm trying to save a picture from byte arrays using RandomAccessFile. The file appears but doesn't open (like its corrupted).
I'm using the bittorent protocol which gives a SHA-1 hash that I compare all the bytes with to verify the data. All the bytes pass the hash check and all the hashes are checked. So I'm pretty sure I'm getting all the bytes correctly.
Is there anything I can do that could tell what's going wrong?
public RUBTClient(final TorrentInfo2 tInfo, final String outFileName) { ... this.outFileName = outFileName; File destined = new File(outFileName); try { destined_file = new RandomAccessFile(destined, "rw"); destined_file.setLength(tInfo.file_length); } catch (FileNotFoundException e1) {
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)
How would I get java to generate a random number from 0-2? all I've been able to find on random numbers is math.random which gives you from .0 to .10. you can multiply this by 10 to get 1-10 or by 100 to get 1-100 but how to make it so java will simply let me tell it the rand of numbers I want or get a random number in a range that is not a multiple of 10. and I can't seem to find anything about it anywhere.
I'm trying to use a setter method to pick a random integer to be the MPG for a car. However, I'm having major issues in my driver when trying to use that random number in an instance. I'm not finished with the driver yet because I keep getting "cannot find symbol errors"
import java.util.Random; public class Car { private String make; private String model; private int year; private int mpg; private int odometer; Random generator = new Random();
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;
I am wanting this program to prompt the user to enter a maximum value and a minimum value and the program should in theory generate a random number for the output. Here is my logic:
int maxRange1; int minRange1; static int range; static Random gen;
Then in my mail argument:
gen = new Random(); Scanner input = new Scanner(System.in); System.out.print("Enter the maximum number: "); int maxRange1 = input.nextInt();
[Code] ....
I am able to return both the user prompts and get the inputted answer to appear but I am not getting a response for the prompt "The random number is: ".
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);
I am very new to programming. This is for a college assignment. It says in the brief of the assignment that we will need to convert Math.random to output a random number between 1-1000. How can I do this?
I am trying to build a Jpanel that when you click the button it generates a random number between one and 100 and then display that number on the screen. It is supposed to start with a label that says Press the button to generate a random number between 1 and 100 and then when you press the button it changes the label to the random number generated. Everything has worked so far except the fact that it will not display the random number generated. It shows the button and the original string but it does't change it to the random number. Here is my code
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class RandomNumberPanel extends JPanel { private JButton RandomNumber; private JLabel label;
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?
I created the a Time class, a Random number class, and Node class. The thing is when i run the Node class its suppose to spit out a random number and tell me the time it spit it out in nano time. The thing is i cant get the nano time to appear at the time the number was generated. This is my assignment
1) A “MyNum” class that will generate a random integer number from 1 to 200.
2) A “Time” class that will return the system time with sufficient resolution to show the time between insertions. I suggest System.nanoTime().
3) A “Node” class that will encapsulate the integer number and the Time it was generated.
4) And a “Storage class” class that will contain the all the SORTED Nodes using an insertion sort. a. This class should have a “add” method to add in each node. b. And method(s) so the driver class may display the sorted list of nodes
5) The “main” or driver class.
But what i want for now is to get the node class to run for now. This is the code so far:
public class Time { public static long time() { return System.nanoTime(); } }
The Number class
import java.util.Random; public class MyNum { static Random number = new Random();
I'm trying to write a method that will print a string of a random number of X's (from 5 to 20) on a line, then another number of X's on the next line, etc. until the random number = 16.
I have to use while loops and probably fencepost algorithms. I'm confused with how to print the number of x's the random number of times over and over.
Right now, I'm pretty sure my for loop is wrong or unnecessary.
So far, this is my code:
public static void randomX() { int x = 0; while (x != 16) { x = (int)(Math.random()*20) + 5; for (int i = 0; i <= x; i++); { System.out.print("x"); } } }
Write I program that generates a random number and asks the user to guess what the number is. If the user's guess is higher than the random number, the program should display "Too high, try again." If the user's guess is lower than the random number, the program should display "Too low, try again." The program should use a loop that repeats until the user correctly guesses the random number.
public class NumberGuess { public static void main(String[] args) { // Create a Random object. final static Random rand = new Random(); // max number is the upward bound number final int MAXNUMBER = 10; /** * Method should return a random number within the upward bound MAX_NUMBER.
[code]....
I get compiler error message
NumberGuess.java:25: error: ';' expected int getRandomNumber (); ^ NumberGuess.java:63: error: reached end of file while parsing System.out.println("You got it right in " + numberOfGuesses + " guesses."); ^
Trying to generate random integers, based off user-input for amount of integers, and then sort them into an array. The problem is that the second method needs to be int[] but I cannot figure out what to make the return result. The instructions say it needs to be an int[] in the UML diagram, so I know it's not supposed to be void.
Java Code:
public void generateNewSecret() { Random rand = new Random();{ for (int i=0; i<numDigitsSet; i++) { secretNumber[i]= rand.nextInt(10); System.out.println("" + secretNumber[i]);