I am new to java and i am trying to make a Java application which prints a diamond in a square grid of dots whose side length is input to the application.When you run the code is should be like this:
..*..
.*.*.
*...*
.*.*.
..*..
My java code print this:
..*..
.***.
*****
.***.
..*..
Here is my code:
class Main {
public static void main(String args[]) {
System.out.println("#Enter size of Diamond :");
int longestRow = BIO.getInt();
for(int row=1 ; row<=longestRow ; ++row)
Currently, I am trying to create a program that draws a square anywhere in a 15x15 Quadrant I (Coordinate plane) grid. I am stuck on trying to get the axes displaying correctly. This is the code I have thus far:
import java.util.Scanner; public class Question2square { public static void main(String[] args) { // Axis variables int yAxismin = 0; int yAxismax = 15;
[Code] ....
Unfortunately, instead of drawing the 'L' shaped axes I desire, it displays an 'r' shape instead. I'm trying to figure out how to display the axis properly. I tried flipping the for loops but that didn't work. I don't see what else could be inhibiting this.
I'm trying to create a cursor for a game that moves square by square. While it will move to the next square, though, it leaves the image of the previous cursor on the last square it was on.
As a visual explanation, this is what the program looks like on launch:
This is what it's suppose to look like after you press the right arrow key once (made by forcibly changing launch coordinates):
And this is what it actually looks like after you press the right arrow key once:
Here is the code for the program:
package cursortest; import javax.swing.*; import java.awt.*; import javax.imageio.*; import java.io.*; import java.awt.event.*; public class CursorTest extends JPanel implements KeyListener{
[Code] ......
I'm fully aware that I could just use g.clearRect on the area and remove it for sure, but I know for a fact I shouldn't have to as I have another program I made a long time ago that tried to do something similar without needing to resort to that.
So I am learning HashMaps/Arraylists and I can't really understand the diamond operator or what it's for. Take the following code for example: Why could we not just do this without the diamond?
Java Code:
import java.util.HashMap; class Untitled { public static void main(String[] args) { HashMap<String, String> map = new HashMap<String, String>();
Write a program that reads an integer and displays, using asterisks, a filled diamond of the given side length. For example, if the side length is 4 the program should display.
* *** ***** ******* ***** *** *
I have it where it displays the top half of the diamond. But i cannot figure out how to get it to draw the bottom half.
import java.util.*; public class E616 { public static void main(String[] args) { Scanner input=new Scanner(System.in); System.out.print("Enter number of rows. "); int N=input.nextInt();
I am new to learning Java and I am trying to print an unfilled diamond using asterisks. The height of the diamond has to be based on user input. My code currently prints out a filled diamond based on user input but I cannot figure out how to print an unfilled one. Every time I change one of the loops it messes something else up.
[public static void diamond(){ int i = 0; int j = 0; int k = 0; int height = 0;
I wrote this (for the variable name, this is just a small part of my program and I'm trying to get the pattern right so I didn't mind my variables at the moment):
Java Code:
public class NewFile{ public static void main(String []args){ int k = 0; for (int i=1 ; i<=5 ; i++) { { for (int h=2 ; h >= i ; h--)
I realize I should divide the code into a lower and upper triangle using two loops. However, I don't know how to break the first part. I did find the "trend" but I don't see how to implement it.
I am making a basic calculator using SWING.I want my JTextField to stretch across the top, above my buttons. All I can seem to get is it be the same size as one of my buttons.
How to implement GridLayout. In my applet, I want to make a grid of 2 rows and 2 columns. In each grid I want to add a Label and a TextField. I want the background to be red.
So my code would be?
import java.awt.*; import java.applet.*; import java.awt.event.*; public class GridLayoutApplet extends Applet implements ActionListener{ // construct components Label fNameLabel = new Label("First Name"); TextField fNameField = new TextField(20);
[Code] .....
I have read about panels and frames but, it is all confusing to me. How can you add a label and a TextField to one square of the grid?
I am currently trying to write a method for checking to see if an "agent" in a cell (place in a 2d array) is satisfied. So, the assignment is a 2D array that can have a blank space, an O, or a X as a character that fills a particular space. An agent is satisfied if it has similar characters around it in a percentage that is higher than the threshold. For example, if the threshold was 60% and a cell that had an X in it, had 3 X's around it and 2 O's, then it would be satisfied because 3/5>=60%. For my code, I tried using if and else statements to isolate circumstances in the corner of the grid, the edges, and everything in between.
public static boolean isSatisfied(char[][] tissue, int row, int col, int threshold){ char check= tissue[row][col]; if (check==' '){ return true; } else{ int countx = 0; int count = 0;
So I'm making a calculator using JFrame and that stuff and I need figuring out the GridLayouts. I'm not doing this for homework or anything just for fun. I don't need all the grid layouts.
The point is to use a binary search to determine how many steps it would take to get to int X, int Y in a grid that is N by N. Picture a parking lot that is square and your car is at (x,y). You can honk your horn from your key to determine the direction of the car. I need to return the amount of steps to get to the car. You can't step diagonally. I am currently getting an error that causes an infinite loop and I can't fix it.
public class ParkingLot { public int search(int N, int X, int Y) { int minX = 0, maxY = N, minY = 0, maxX = N; int num = 0; int curX, curY; int newCurX, newCurY; curX = (minX + maxX)/2; curY = (minY + maxY)/2; while (curX != X || curY != Y)
I wanted to know which RAD TOOL should I use to make the grid. I used the label but it's not interesting like the game *. I m starting to make the game and can't think how to make the grid.
Thought of using the buttons but can't add image to it.
what should I use to make the grid.
* what I did earlier Is place 9 label in grid form (just to test) and nine buttons one for each. When u click a button, image is shown in respective label... But it doesn't feel like u r playing game..
I have a question about updating a grid during runtime in GridWorld. I'm making a game called Flood-It (basically, you click on squares to change their color and attempt to get all of the squares the same color in the grid) and I'm having trouble with changing the grid size. I made my own world class, called CellWorld.
Whenever a user wants to change the grid size after playing the game, this is supposed to set the grid to the new updated size, but it never changes in the actual game, i.e. the user just won a 2x2 game, attempts to change the size to 10x10, but the grid stays 2x2. By debug testing, I can say for certain that everything else works, such as the maxStepCalc and loading the grid. The only issue is the new grid not showing up.
how to create coordinates in a two-dimensional grid, in the end it shall look like A5, F6 and so on. The aim is to place 3 DotComs in this grid by coincidence. To do this one uses two arrays. One array represents one DotCom, the other represents the grid's size, in this case 49 (7x7).The code ends like this:
ArrayList<String> alphaCells = new ArrayList<String>(); ... int x = 0; int row = 0; int column = 0; while (x<comSize) { grid[coords[x]] = 1; // mark master grid points as used row = (int)(coords[x] / gridLength); column = coords[x] % gridLength; temp = String.valueOf(alphabet.charAt(column)); alphaCells.add(temp.concat(Integer.toString(row)); x++; } return alphaCells; }
why row and column are calculated like this. Furthermore I don't understand why the column is used to generate a character, because columns are marked with numbers and rows are marked with characters.
import java.awt.GridLayout; import javax.swing.*; public class Screen { JButton start; JButton reset; JButton box[][] = new JButton[20][20];
[Code] ....
I am trying to place the buttons on the bottom. I tried a few different things but the grid layout keeps grabbing it and making them a part of the grid at the button.