Diamond In A Square Grid Of Dots
Nov 14, 2014
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)
[Code] .....
View Replies
ADVERTISEMENT
Feb 3, 2015
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.
View Replies
View Related
Aug 31, 2014
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.
View Replies
View Related
Aug 15, 2014
why we use only three dots(...) in vararg method???
View Replies
View Related
Feb 20, 2014
How would I compare the square of the square root of any number. The difference in these values is due to the rounding error in Java.
Example: Enter number 2
The answer I should get is: 2.000000000000004
Round off error: -4.440892
View Replies
View Related
Mar 26, 2014
I am currently trying to print a Diamond using for-loops but I seem to be confusing my self / over-complicating it.
This is what I have so far [URL]). When I run the code I get [URL].
I want to duplicate it on to the other side but I can't seem to be able to figure out a working for-loop to print it out.
Also, is there a faster/efficient method of doing something like this?
View Replies
View Related
Nov 19, 2014
I am pretty close to finishing the diamond but I cant figure out how to print the bottom right. I have to use a for loop and if/else statements.
public static void main(String[] args) {
int input = 0;
input = getSize(input);
char[][] array = new char[input][input];
System.out.println("
Diamond:");
createDiamond(array, input);
print(array);
[code]....
View Replies
View Related
Oct 11, 2014
i want solution to my program
View Replies
View Related
Mar 8, 2015
I'm currently trying to do a diamond using Polygon. I have done this so far. It is not drawing a diamond.
import java.applet.Applet;
import java.awt.Graphics;
public class Diamond extends Applet {
int[] a = {-30, 100 , 30, 100};
int[] b = {100, 40, 100, -40};
public void init()
{
}
public void paint(Graphics g)
{
g.drawPolygon(a, b, 4);
}
View Replies
View Related
Jul 8, 2014
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>();
map.put("California","Sacramento");
map.put("Oregon","Salem");
map.put("Washington","Olympia");
System.out.println(map);
}
} mh_sh_highlight_all('java');
View Replies
View Related
Oct 14, 2014
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();
[code]...
View Replies
View Related
Jan 31, 2015
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;
[code]...
View Replies
View Related
Mar 23, 2015
I have to make a pattern that is of a diamond shape such as this:
Java Code:
1
1 2 3
1 2 3 4 5
1 2 3
1
mh_sh_highlight_all('java');
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--)
[Code] ....
My output is the following:
Java Code:
1
123
12345
1234567
123456789
mh_sh_highlight_all('java');
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.
View Replies
View Related
Oct 5, 2014
My son want to create a java program (Diamond shape) that can plot graph for with the following data.
Pattern type is:
* *
* *
*
* *
* *
*
View Replies
View Related
Jan 13, 2015
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.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
[code]...
View Replies
View Related
Mar 13, 2014
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?
View Replies
View Related
Nov 22, 2014
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;
[Code] ....
View Replies
View Related
Aug 19, 2014
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.
View Replies
View Related
Sep 15, 2014
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)
[code]....
View Replies
View Related
May 27, 2015
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..
View Replies
View Related
Jun 5, 2014
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.
import info.gridworld.actor.*;
import java.util.ArrayList;
import info.gridworld.grid.Location;
import java.awt.Color;
import javax.swing.JOptionPane;
[code]...
Now, let me narrow down the issue. It is in the runner class:
world.setGrid(new BoundedGrid<Actor>(world.getLength(),world.getWidth()));
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.
View Replies
View Related
Mar 28, 2014
I am making a RTS game in Pure Java, and no libraries. So pretty much I want a constructor like so
Java Code: new Grid(40, 40) mh_sh_highlight_all('java');
That will create a 40x40 grid of a certain size per cell. Then I would like to fill the empty cells, and also be able to place things on top of them.
Also, I would like a tilt similar to Clash of Clans. How do I do this?
View Replies
View Related
Nov 19, 2014
Is it possible to put Jlabels in to a grid Layout on a Panel in a Jinternal frame
View Replies
View Related
Aug 22, 2014
Working with some code that displays the random movement of an object such as Move 1: (0,1) Move 2: (10,99)?
I need these methods in the class
void initialize( int xPos, int yPos)
void moveLeft()
void moveRight()
void moveUp()
void moveDown()
int getXPosition()
int getYPosition()
View Replies
View Related
Mar 16, 2015
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.
View Replies
View Related
May 20, 2014
Java Code:
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.
View Replies
View Related