How can I find the overall averages of the columns in this array?when i run my code it gives me an output that looks like this (showing me wrong averages): 0 1 2 3 overall grade
I am very new to Java Swing. I have to create a TreeTable in Java Swing with a Parent Row having say 6 columns and its all child row having just 4 columns. like shown below
public static void displayOutputs (int[][] anArray) { System.out.println("Here is your 2Dim array:"); for (int i = 0; i < anArray.length; i++) { System.out.println(Arrays.deepToString(anArray)); } }
This is my code and I get this as a result when I input 10,20,30,...,90 into array[0][0], array[0][1], ..., array[2][2] (3rows, 3columns array)
[[10, 20, 30], [40, 50, 60], [70, 80, 90]]
[[10, 20, 30], [40, 50, 60], [70, 80, 90]]
[[10, 20, 30], [40, 50, 60], [70, 80, 90]]
While I expect to get only
[10, 20, 30]
[40, 50, 60]
[70, 80, 90]
I get no errors at least when I have the same # of rows and # of columns. However, when I have more columns than rows, a compiler stops running when it runs columnSum method.Here's an error message.
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2 at lab10.Array2DMethods.columnSum(Arrays2DDemo.java:70) at lab10.Arrays2DDemo.main(Arrays2DDemo.java:111) Java Result: 1
And here's my code
public static void columnSum (int[][] anArray) { int sum =0; for (int col=0; col < anArray.length; col++) { sum=0; for (int r = 0; r < anArray[col].length; r++ ){ sum += anArray[r][col]; } System.out.println("Sum of column " + col + " = " + sum); } }
why my code doesn't work when I have more columns.
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 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 ?
I am making a gradebook program that calculates the averages of 25 students using 2D arrays in which the students have four test grades. I have figured out how to display the averages of each student in one column but I cant seem to figure out how to display the letter grade of the average into another column.
Right now my program reads from a .txt doc
Heres what I've got.
TestGradeBook.java
import java.util.*; import java.io.*; public class TestGradeBook { public static void main (String [] args ) throws IOException{ //Declarations final int ROWS = 100; final int TESTS = 4;
[Code] .....
GradeBook_Data.txt Name100100100100 // basic name and grades
i am fairly new to java but have made a few projects so i do know most aspects that would allow me to complete the task its just i have been stuck at the same place now for 2 days.The project is to create a java program that can read specific data within a csv file to work out the averages etc. The csv file is a database of different weather stats . an example of the first 12 months of the csv file is below..
I know that once the data is indexed i can than use a double to find the average of the 12 specific pieces of data and so on. once this is complete i should than be able to transfer the data to a simple graph.
I am taking the Class Algorithms and Datastructures and got an assignment for Lab that really throws me off. The goal is to create an Array out of a given CSV file, implement several Methods that get the size of array, etc.
I am still stuck in the first part where the CSV has to be imported into the Array. My problem is that I need a mechanism that figures out the needed size for the Array, creates the array, and only then transfers the data from the CSV.
The list consists of the following wifi related values:
MAC-Adress, SSID, Timestamp, Signalstrength.
These are on the list, separated by comma. The Columns are each of these, and the rows are the four types of values making up the information on a certain wifi network.
The catch is, we are not allowed to use any of the following:
java.util.ArrayList java.util.Arrays and any class out of java.util.Collection.
So far I used the BufferedReader to read in the file and tried to implement the array, but I get an arrayindexoutofboundsexception.
Below is my Code (Its still an active construction zone):
public class WhatsThere { public WhatsThere(String wifiscan) throws IOException { } public static void main(String[] args) throws IOException { // WhatsThere Liste = new WhatsThere(String wifiscan); String[][] arrayListe = new String[0][0];
So as part of my program I have to find the corners of an array (the array can vary in size but is always square) but I'm not exactly sure how to do this. I thought of one possible way but I am not sure if I can do it or how to write it,
if array[row][col] = [0][0] or [row length][col length] or [0][col length] or [row length][col length].
I'm just giving examples of what I am trying to find here I know none of these are actual syntax. I don't even know if I can check whether an array's coordinates are equal to coordinates on that array or not. How I can write this or if there is another way to do it? If yes, what about edges of the array?
I have a given array of numbers, and I have to find the longest decreasing sub-array, but the thing is that the elements don't have to be next to each other!
For example, the longest decreasing sub-array for this array : 546 -156 165 -156 -56 -13 5
is 3 (check the bold numbers)
Until now, I have nearly finished my code, but I have one problem...
private static int decreasing(int[] a) { int result=1, temp=0, br=1; //Checking all the elements one by one: for(int i=0;i<a.length;i++){ temp=a[i]; //placing the element on a temp value
[Code] ....
The problem with this code is that it's not smart.. let's say I have : 100 -500 90 80 70
Once it hits -500, none of the other if's with pass....
what I needed to know to complete the lesson, but now it just tells me what the output should be and I have to research the information on my own. anyways, here is my code from the previous lesson:
import java.util.Random; import java.util.Scanner; public class tnArray { public static void main(String[] args) { int [] array;
[code]....
Now I have to change it so that instead of counting the number of times a number will appear in the array, I must output which slot in the array the number is in.
So what I'm trying to do is write a code in java which finds a path through a maze. I want it to go through the maze and determine if there's a * symbol at that location or not. If there is a * symbol at the specified location then the program would search for another position until it finds one without the * symbol and if it can't then I'll have the program return null. I also want it to implement backtracking which I'm not sure how to do. Here's my code so far
private boolean findPath(int fromRow, int fromCol, int toRow, int toCol){ boolean solved = true; for(int i=fromRow; i<toRow; i++){ for(int j=fromCol; j<toCol; j++){ if (x[i][j] == ('*')){ //do something } } } return false; }
the code isn't finished yet however what I'm not sure is what do I do with the if statement and how do I implement backtracking?
An array which contain a list of names. I let for a user input and I use that to search through the array. For example lets say the string name "Christian" is stored inside the names array and the user types in Chri, the program looks in the array and finds a name that contains Chri and prints them out. How do I go about doing this?
I have 2 arrays in random order of 10 numbers.I need to find the biggest number from array A and B and then when its on a screen second thing is to multiply those numbers by 2.
import java.util.Random; public class Projektas { public static void main(String arng[]){ int i,j; int A[] = new int [10]; int B[] = new int [10];;
I made a method which takes values from a data set and finds out which one is the highest value. When it finds the highest value, it returns the country which is associated with the value. Here's the data set.
"Country""Total CO2 2005 (million tonnes)""Road CO2 (million tonnes)""Road CO2 per person (tonnes)""Cars per 1000 people" 10 USA5951.131530.35.16777 UK2573.4119.681.99470 Italy476.08116.862592 Germany841.78150.211.82550 Canada553.02123.423.82562 France414.03128.132.04477 Russia1575.44114.690.8178 Japan1254.47224.241.76447 China5100.6228.020.317 India1147.4691.060.18
So if the number was 5951.13 then the program would return USA. How do I do that? I've already started on trying to get this code to work but it doesn't seem to compiler so what's wrong with it?
public static CO2Data highest (CO2Data [] arr2){ Scanner sc = new Scanner(System.in); CO2Data highestindex = arr2[0]; CO2Data currentcountry = arr2[0].getCountry(sc.nextLine());
[Code] ....
Also the array is a CO2Data array which is part of the following class:
public class CO2Data { //The CO2Data class will be called in other methods
private String country; //A private variable will prevent other users from accessing and changing these variables.
private double totalCO2; private double roadCO2; private double CO2PerPerson; private int carsPerPerson; public CO2Data() { country = "";//this sets the initial values for the different variables
The program below is intended to find the arithmetic mean of the numbers stored in the array q in two ways: once by storing the numbers in an ArrayList d, where you allow all the necessary conversions to be performed automatically; and once by storing them in an ArrayList e, where you perform all the conversions by hand. Complete the program.
Here is what I have so far:
double[] q = { 0.5, 2.4, 7.4, 2.8, -6.2 }; ArrayList<Double> d = new ArrayList<Double>(); ArrayList<Double> e = new ArrayList<Double>(); for ( double x : q ) { d.add( x ); e.add ( new Double ( x ) );
[Code] .....
Why does it still show "a / d.size?" I thought I fixed that. Whatever, it's supposed to be "dTotal / d.size()", etc.
This is my code up to now and I can't do anything to make it work. I want it to tell me how many times the number 3 appears, and the last position it was in. I am getting errors like"Cuanto.java:88: getPosition(double[],double) in Cuanto cannot be applied to (double) ....
a = getPosition(a);" and unreachable statements, and value not found. It's all over the place every time I make a change to it.
Java Code:
public class Cuanto { static int getPosition(int count,double listOfValues[], double targetValue) { int a = 0, i; for (i=0; i < listOfValues.length; i++) { if (listOfValues[i] == targetValue) { a++;
So in this program, which is a grading program, I am trying to compare all the students averages to find who has the highest one and list the grades and the student's names from least to greatest. Yes, I see there are other problems in the program but it is nowhere near finished.
import java.util.Scanner; public class Main { public static void main(String[] args) { String[] studentName = new String[20]; int[] studentAverage = new int[20]; Scanner input = new Scanner(System.in);
import java.io.IOException; public class Largestcolumn { public static void main ( String[] args ) throws IOException { int largest = 0; int newnumber = 0; int[][] data = { {3, 2, 5},
[Code] ....
When I run this code, I get this following output: The largest element in column 0 is: 9. Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4 at largestcolumn.Largestcolumn.main(Largestcolumn.java:27) Java Result: 1
It outputs the first column's maximum element but then throws an out of bounds error. I'm new to Java and I can't figure out how to fix my code so that it will work for this multidimensional array and output the maximum elements in all of the columns.
I'm required to create a program that finds the minimum value in an Array of integers.
Here is my approach :
public class Person { public static void main(String [ ] args){ int theArray[]=new int [10]; int result = 0; for (int i:theArray){ if (i < Integer.MAX_VALUE)
[Code]...
I can't really progress from this position. I keep getting told to change the return type to int on main method, then when i do it says change it to void..