I need to write a class,that will give me output like this:
*
***
****
***
*
I have to use for loop,i know that i have to use nested for loops, for rows and columns. I just cant figure it out the thing with spaces,and how to turn it to count back.
I have a 5x5 array of which I read from an external file and I am supposed to print out the original matrix and then add up each row and column, proceeding to store them into the sixth positions in my matrix. After that I print out the new matrix.
I am confused as to how to isolate rows and print them out. I know how to add the entire matrix up but isolation is my issue.
Here is what I have including how to read the matrix and the sum of the whole thing
import java.io.*; import java.util.*; public class prog470cAddingRandC { public static void main (String [] args) { //read the file Scanner inFile=null;
I am making rows and columns in the form of a multiplication table, listed below is my code:
package assignments; public class MultTable { public static void main (String [] args) { int row, column, x, y; for(row = 0; row < 8; row++)
[Code] .....
If you see my sample run you can see that I have the multiplication table down but, I haven't completed it. I have to make the bottom left half of the whole table blank somehow. For example, I have to make it halfway through the middle of the table the bottom left half full of white space...
5 6 7 8 9 12 14 16 18 21 24 27 32 36 90
hm, it's supposed to be the other way around horizontally.
How to sort data from a .csv file. The file has a column that contains duplicate groups, and a column that has duplicate employee id's. I need to take the data and sort it into rows. The employee's id will be in the first column, then the groups the employees belong in will occupy the following columns. The groups and employees are dynamic.
groups| empId ----------------- Group A| a1234 | Group A| e3456 | Group A| w3452 | Group A| d3456 | Group A| j7689 | [Code] ....
I want to format the .csv as follows:
-------------------------- empId | group 1 | group 2 | -------------------------- a1234 | group A | group B | --------------------------- w3452 | group A | group B | ---------------------------
I am continuing on in trying to build up the basics of matrix algebra from scratch.
I have created an object class called Matrix
import java.util.ArrayList; public class Matrix { public int NumRows; public int NumColumns;
// This array contains the entries of our matrix. ArrayList<Double> entry = new ArrayList<Double>();
[Code] ......
Bottom line: a matrix has a number of rows and a number of columns, and for each pair of row and column, we have a number in our matrix. The DisplayMatrix method prints my matrix to the screen, and the GetEntry method returns a particular value. This all works fine and dandy as far as I can tell.
A fundamental operation done to matrices to obtain a special matrix called the RREF is the process of switching 2 rows. Here is a method I have written that switches two rows of a matrix, and outputs the result as a new matrix. Note that I want the original matrix to be unchanged.
// Switch two rows public static Matrix SwapRows(Matrix A, int r1, int r2){ if(r1<1 || r1>A.NumRows || r2<1 || r2>A.NumRows) PRINTLN("illegally switching rows"); Matrix C = A; double dummy[] = new double[A.NumColumns];
[Code] ....
How I call this, inside a public static void main(String[] args), is as follows:
// Declares that A is a 2 by 2 matrix. Matrix A = new Matrix(2,2);
// We now add values in. The top left entry of A is 4, the top right entry of A is 1, the bottom left entry of A is 2, and the bottom right entry of A is 6.
double pony[]= new double[4]; pony[0]=4; pony[1]=1; pony[2]=2; pony[3]=6; A.AddEntries(pony);
// We can display the matrix in the output, and it looks exactly as expected!
A.DisplayMatrix();
// I am now going to create a new matrix called B. It is going to be obtained by flipping the first and second rows of A.
//Note that I want A is stay as I initialized it.
//I dont want A to have it's 2 rows switched. I want B to the matrix obtained by switching two rows of A.
Matrix B=SwapRows(A,1,2); B.DisplayMatrix();
// Displaying B gives me the desired result. However, if I now display A again, it is the same as B.
A.DisplayMatrix();
Why is my matrix A being modified? Of course, I am more than capable of providing more details/comments if requested. I suspect that this is a super silly mistake.
I am trying to write a code for multidimensional array, allocate memory for variables and access the value of the arrays. I want them to be shown as rows and columns. but my code only shows one column and no rows. here is my code:
public static void main(String[] args) { int[ ][ ] aryNumbers = new int[2][2]; aryNumbers [0][0] = 1; aryNumbers [0][1] = 2; aryNumbers [1][0] = 3; aryNumbers [1][1] = 4; int rows = 2; int columns = 2;
I have an application that displays a GUI and this GUI displays a table with several columns and rows. I have a class that extends DefaultTableModel. I wrote the code that displays the GUI. When the database table changes, how would I updated the GUI dynamically? Do you have any sample code that does that?
i'd been using Opencsv to upload all this data into my Db(Postgres) using EclipseLink with batch inserting, it wont take more than 5 secs to load 200k+ data cause all the columns are of type string so theres no format require, the problem comes when i need to give a special format to the data that is in this table (date, Integer, etc).
Right now how it works:
- Ill go row by row (when its required) verifying the format of the data and convert it with something like this Ex: Date date = Fechas.strToDate(data, Pattern) and fill the new Object with this info
what i'm planing to do
- With the function of EclipseLink OPERATOR im gonna use that to change all the rows of a column that requires a NUMBER format with OPERATOR('ToNumber',column1,'9999999999')
i cant do the same for Date cause ill get an error if the data doesn't have a Date like pattern
how to handle this Date formatting(from a query, or directly in java).
I wrote this code which print a black image depends on the number of rows and columns you give it
public class BlackImg { private Mycolor[][] colorArr; //Mycolor is a class i wrote that represents colors. // no need for showing the class here. // so i created here an array of type Mycolor, for example: // { {(255,255,255), {(127,127,0)} }
[Code] .....
my problem is that my output comes good except the last line ,
Output: (0,0,0) (0,0,0) (0,0,0) (0,0,0) (0,0,0) (0,0,0) (0,0,0) (0,0,0) (0,0,0) (0,0,0) (0,0,0) (0,0,0) BlackImg@1db9742 //what is this line , why does it showing up ?
how a nested for loop increments the outer loop and then the inner loop and then when it runs the inside code.I've ran the program a few times but I'm just not understanding it, need little narrative to it?
Im trying to create a checkerboard pattern with 2 nested for loops . I need to output asterisk characters. Im supposed o use an n int so I dont know if im limited to that 1 int. Im only getting 1 line of asterisk.
* * * * * * * * * * * * * * * * * * * * package checkerboard; public class Checkerboard { public static void main(String[] args) { for (int row = 1; row < 6; row++){ System.out.print("* "); for (int col = 6; col < col; col++) {
// Demonstrate a two-dimensional array class TwoDArray { public static void main(String args[]) { int twoD[] [] = new int[4] [5]; int i, j, k = 0;
[Code] .....
Output:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
(1) I don't understand how repeating the loop creates the structure of the output. Taking the second loop away and putting the "System.out.print(twoD[i] [j] + " " );" under k++ creates the output to print a number on each line. How do I write the code not having the second loop, assigning k to each value that is moved through the grid then printing it out but having the output the same?
So I cant figure out why my output for my for loop isn't working properly. So the output for the square comes out right but the for loop isn't working properly for the H. I have tried to figure it out and it should go to the next line but its not.
import java.util.Scanner; public class Random { public static void main(String [ ] args) {
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.
Question: 1. Declare and implement a class named Substrings. The class will contain the following data members and methods:
Data members: string S
Methods: setS() take a string as a parameter and store it in S printSub1(), printSub2(), printSub3(), printSub4() print all substrings of S. If S = "abcd",
Alright so after doing some googling and watching tutorials I managed to put together the first two but I still don't exactly understand how nested for loops work, however just a single loop I do understand.
Secondly, the 3rd and 4th prints are completely destroying my brain using for loops, which we are supposed to use. Check out my code below, also keep in mind the 3rd is giving errors and the 4th i had to revert back to the same as the first print temporarily because my code because so messed up. How to understand nested for loops better.
[code=Java]
import java.util.Scanner; class subString { String S; void setSubstring(String SS) { S = SS;
[Code] .....
Compiling: error for myS.printSub3 and myS.printSub4 is the same as 1 because i had to revert it after ruining the code.
So basically i have to read from a text file and get some information back from that and print to screen. Im quite confused and im not sure what loop i should use first to scan the text and receive certain information back?
Nested for-loops always throw me in a loop.I found a snippet that uses 2 for-loops to check if there is a duplicate element in the array:
/* * brute force way of checking if array contains duplicates in Java comparing each elements to all other elements of array complexity on order of O(n^2) not advised in production */ public static boolean bruteforce(String[] input) { for (int i = 0; i < input.length; i++) { for (int j = 0; j < input.length; j++) { if (input[i].equals(input[j]) && i != j) { return true; } } } return false; }
Let us say we have: String[] input = new String[] {"one","two","three","one"}
I'm having problems with the mid section of the rocket, specifically the bottom part of the mid section:
|../..../..| |.//..//.| |//////|
I'm having difficulty writing the for loop to correctly print the dots. You're supposed to incorporate a constant which allows you to adjust the size of the overall figure. The loop doesn't work when I adjust the size, only when the value of HEIGHT is 3. The loop, however, for some reason works with the top part of the mid section.
This is the for loop for the top section.
for (int dots = 1; dots <= -1 * line + 1 * HEIGHT; dots++) { System.out.print("."); }
This is the for loop for the bottom section.
for (int dots = -1 * line + 1 * HEIGHT; dots <= 1; dots++) { System.out.print("."); }
Usually reversing the iteration of the loop just requires flipping the conditions, right? But it didn't work this time for some reason. Why this doesn't work? I can post the code to my entire program for compiling.
When input validation for the first months rainfall is non-negative, this results in correct average rainfall.
When input validation is used for the first months rainfall I'm prompted to input a positive number, which is 2.
When asked to input rainfall, in inches, for each month, I begin with input -3, I am again prompted to re-enter a positive, I enter 3. What happens is, whichever positive integer I input after I had entered a negative for the first months rainfall, the average would be off by the positive number inputted.
package averagerainfall; import java.util.Scanner; public class AverageRainfall { public static void main(String[] args) { int maxYears; int totalMonths;