I have to create a square matrix that has a min and max value as well as a size value which is given a integer value in the main method. The matrix has to be filled with random values. Also I have to add that matrix to another one in an addMatrix method and I have to subtract both in a subMatrix method. These are the requirements:
Methods:
Constructor() - receives the row and col size for myMatrix and a max and min values for range of random fill values for the matrix.
RandFill() - fills matrices with random numbers
addMatrix() - receives a matrix object. adds its myMatrix with the received object's myMatrix. The result is placed in this object's myResultMatrix.
subMatrix() - subtracts both matrices
I typed up this code but I'm not sure about some parts of it and I would creating min and max values in the Random method and in the main printing the separate 2 matrices and adding and subtracting them:
import java.util.*;
public class SquareMatrix2 {
public int size;
public int myMatrix [][];
public int myResultMatrix;
public int [][] ResultStatus;
When taking in these numbers from the user, I am not allowed to let the user state what size the matrix is (e.g.;3 x 3). Instead the program needs to determine that itself. I have written the code below to count the number of numbers inputted, but now I am stuck as to how to get them into the array. I have what is suppose to be my array written, but it is not function yet.
import java.util.*; public class MagicSquare { public static void main(String[] args) { Scanner input = new Scanner(System.in);
I am making a Sudoku game and creating a matrix of JTextFields. However I am getting the following errors
Exception in thread "main" java.lang.NullPointerException at SudokuView.board(SudokuView.java:30) at SudokuView.<init>(SudokuView.java:18) at SudokuMain.main(SudokuMain.java:5)
I know the problem is with this code
box[i][j] = new JTextField(); panel.add(box[i][j]);
I know this because when I do this:
panel.add(new JTextField());
It works. However it puzzles me why it is not working.
Whole Code:
import java.awt.GridLayout; import javax.swing.*; public class SudokuView { JFrame frame; JPanel panelBoard; JTextField[][] box; int row=10; int col=10; SudokuView(){ frame = new JFrame("Play Sudoku GOOD LUCK");
I have to create 3 JLabel for Option, Square and Direction. Well, I did but its not in the right place. It should be in the right Panel but i did change the code so its in panelRight1 but its still not changing? Its somehow not working and no matter how i try to change the position of it, it doesnt change at all.
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class CBallMaze extends JFrame implements ActionListener { /** * */ private JMenu[] menu = {
I'm trying to get my matrix1 and matrix2 to add up to create a third matrix, I've gotten that down, but now I'm just having some trouble getting it to print out the matrix1, matrix2 and then the final matrix3 or the result matrix?
import java.util.Scanner; public class Exercise_7_5{ public static void main(String[] args){ Scanner input = new Scanner(System.in); System.out.print("Enter Matrix 1: "); double[][] matrix1 = new double [3][3];
I am required to read user input to create two matrices which will eventually be added together. I am unsure as to how I can read the input from the user as an int and not a String. The input is from size 0-10 for both column and row size. Also, can you have a new button created in the actionPerformed method of a previous button?
import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.*; public class Matrices implements ActionListener { private JFrame win1, win2, win3, win4;
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.
I'm having a small issue with my output on my code. here is what my output is: The magic value for your square is 34, which means that every row, column and diagonal of your square must add up to that number.
Please enter the 4 values for row 0, separated by spaces: 1 2 15 16 Please enter the 4 values for row 1, separated by spaces: 13 14 3 4 Please enter the 4 values for row 2, separated by spaces: 12 7 10 5 Please enter the 4 values for row 3, separated by spaces: 8 11 6 9 Checking square for problems: DIAG: VALID ROWS: VALID COLS: VALID RANG: VALID MAGIC: No
MAGIC should be YES. However i keep getting it saying no.This is the correct output..The magic value for your square is 34, which means that every row, column and diagonal of your square must add up to that number.
Please enter the 4 values for row 0, separated by spaces: 1 2 15 16 Please enter the 4 values for row 1, separated by spaces: 13 14 3 4 Please enter the 4 values for row 2, separated by spaces: 12 7 10 5 Please enter the 4 values for row 3, separated by spaces: 8 11 6 9
import java.util.Scanner; public class pdonahue_Magic { public static void main(String args[]) { int[][] theSquare = new int[4][4]; Scanner s = new Scanner(System.in); System.out.println.
("The magic value for your square is 34, which means that every row, column and diagonal of your square must add up to that number.");
System.out.print("Please enter the 4 values for row 0, separated by spaces: "); theSquare[0][0] = s.nextInt(); theSquare[1][0] = s.nextInt(); theSquare[2][0] = s.nextInt(); theSquare[3][0] = s.nextInt();
(Square numbers) Find the first ten square numbers that are greater than Long.MAX_VALUE . A square number is a number in the form of n 2 . For example, 4, 9, and 16 are square numbers. Find an efficient approach to run your program fast.
I found two ways of solving this but i think both are way inefficient :
-A square number can be divided in lesser square numbers :
what's the square of 36 ? 36 is 2 * 3 * 2 * 3 => 4 * 9 => square is 2 * 3
-second option is to estimate a number and increase it or decrease it based on how close that number * number is to the BigInteger starting number , as as it gets closer the delta gets smaller until it gets to 1
Why does my program write that i have problem in Timer?
public class Ball extends JPanel implements ActionListener { Timer timer = new Timer (3, this); int x = 0, y = 0, aX = 2, aY = 2; public void PaintComponent(Graphics g){ Graphics2D g2 = (Graphics2D) g;
public class asteriskSquare { public static void main(String[] args) { for (int x = 1; x <= 4; x++){ for (int y = 1; y <= 4; y++){ System.out.println("+"); } System.out.println("+"); } } }
I come to the point: I just started to learn java through various manuals and in one of them I came across a declaration of an array that I do not understand:
int[][] multiArr = new int[2][];
the manual says that you can allocate the multidimensional array multiArr by defining size in only the first square bracket but I can't undestand how you can use this array. Seems to be no way to store data with it!
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)
So currently I'm trying to learn how to draw a square with asterisks based on the input I give for it's sideLength.
So if I have a Square(5) it should draw a 5x5 looking like this:
***** ***** ***** ***** *****
but then in the main method, it should draw multiple squares of given sizes, so say 5, 6, and 7. Making a square for each of the given numbers. This is what I currently have so far ....
class Square { int sideLength; Square( int size ) { sideLength= size; } int getArea() { return sideLength * sideLength;
I am working on a number of utility functions for square matrices and arrays, and I keep having trouble with segmentation faults.
arrayUtils~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ public class ArrayUtils { //This function takes an array a, and returns the sum between indices //i and j, where i is the lower index and j is the upper index. int size makes //sure that the function doesn't go out of bounds. public static int subSum(int[] a,int i, int j) { int sum=0;
My code compiles and runs just fine, i'd just like to get creating a small square box that shows number of words used next to the "word count = ". i'd wanto to press the count words button to count and show the number in the square box. here is my code.
import javax.swing.*; import javax.swing.text.*; import java.io.*; import java.util.*; import java.awt.*; import java.awt.event.*; public class wordCount extends JFrame implements ActionListener
Im trying to get the user to input the rows one by one but my input stops after the first. the examples i looked at in my book had this way i used as well. i are my rows and j are my columns. What is the correct way to do it?
import java.util.Scanner; public class Exercise08_01 { public static void main(String[] args) {
My code then is supposed to read it in and store it as an Array of singly linked lists. I am having trouble with my code, I am only getting outputs where it is only storing the first line of the txt matrixs like so: