I am not getting the result I am looking for, but I'm sure I'm on the right track. I have an array, names + times of marathon runners, and should end up with a program that displays the slowest runner, and the next-slowest runner.
Currently, I get this: The lowest time is 273. The lowest time is 243.
Changing names.length to times.length changes nothing. for (i = 1;... ) changes nothing.
The displayed number should currently only be 243. Why is it displaying 273 first, and at all?
The code:
class Marathon { public static void main (String[] arguments) { String[] names = {"Elena", "Thomas", "Hamilton", "Suzie", "Phil", "Matt", "Alex", "Emma", "John", "James", "Jane", "Emily", "Daniel", "Neda", "Aaron", "Kate"}; int[] times = {341, 273, 278, 329, 445, 402, 388, 275, 243, 334, 412, 393, 299, 343, 317, 265}; int min = times [0]; for (int i = 0; i < times.length; i++) { if (times[i] < min){ min = times[i]; System.out.println("The lowest time is " + min +"."); }
So I have this code to calculate the lowest value of an array:
public class Exercise1 { public static void main(String[] args) { int[] theArray = {1/*/,2,3,4,5,6,7,8,9,10/*/}; int result = Exercise1.min(theArray); System.out.println("The minimum value is: " +result);
[code].....
and I need to write an exception class that should be thrown if the array does not hold any elements.
I am attempting to find the element that holds the lowest time ( i have used System.currentMillisTime ) in the array using a linear search and to then print the times held by the array in lowest to highest order . While i understand how to do a linear search using user input as the key i am not to sure how to do it by initializing a search key in the program to the lowest number and have little experience in using a search in a program that is not a simply linear search. i have attempted to code this, as seen below, but i know i am definitely wrong and i have tried another of different ways even Array.sort and then a binary search .
static long store_MAX[]; // Now an ‘array’ of ints static int deptSize; // Holds the length of the buffer private int shopper_MAX; // Holds the number of items in the buffer
i have to write a method, The method receives a parameter of two-dimensional array of integers. The method returns the number of the column which has the lowest sum of the integers.I'm allowed to use only recursion! no loops allowed!-of course i need to make a private method that will sum a column as a single array and then i have to do another private method that compares the column , but it doesn't really work .
In this project each individual will create a data analysis program that will at a minimum,
1) read data in from a text file, 2) sort data in some way, 3) search the data in some way, 4) perform at least three mathematical manipulations of the data, 5) display results of the data analysis in numeric/textual form, and 6) display graphs of the data. In addition, 7) your program should handle invalid input appropriately and 8) your program should use some "new" feature that you have not been taught explicitly in class.
(Note: this is to give you practice learning new material on your own - a critical skill of today's programmer.) If you do not have a specific plan in mind for your project, below is a specific project that meets all of the qualifications as long as 7) and 8) are addressed in the implementation.
Everything is done except I need to call my methods in my GradeTester.
GradeBook:
/** *This class creates an array called scores. *This class determines the length of the array scores and determines the last grade in the array scores. *This class sorts the array using a bubble sort, and searches the array. *This class calculates the mean, standard deviation, and the median of the grades in the array scores. *Once the grades in the array is sorted, the class then calculates the highest and lowest grades in the array. */
public class GradeBook { public final int MAXARRAY_SZ = 20; double [] scores = new double [MAXARRAY_SZ]; int lastGrade = 0; double mean = 0;
I want to use a method, which takes for example an int and also returns an integer. For example, if the the given integer is strong return a, if it is notstrong return b. How would you write that in a Code?
I want to use that in a more general way. I want to give a method mlong the value X of the type date and let it return an int. Type date consists of 3 int, one of them is the int month.
mlong should return an int depending on the X.moth. at the moment my code looks like this:
// File1: public class date { public int day; public int month; public int year; }
// File 2: public class monthlength { public int mlong(date X) { int t; t = X.month; if (t == 1 || t == 3 || t == 5 || t == 7 || t == 8 || t == 10 || t == 12) { return 31; } if(t == 4 || t == 6 || t == 9 || t == 11) {return 30;} } }
I want to return values from arrays to the main and the problem is i cant use my variables from my constructor, I use new variables in my functions and i know this is no good, when I used the variables from the constructor in my function. I have a compilations errors,also i want to create un object in main and with this object i want to call the functions.
Java Code:
package javaapplication4; import java.util.Scanner; public class JavaApplication4 { public static int[] MyInt; public static double[] MyDouble; public static String[] MyString; public static char[] MyChar;
[Code] .....
The code is working when i run it and i have the right result in my screen but i know this is all wrong with the variables.
I am getting these errors with this code, I can not figure why this error is occuring.
what is the issue with this code?
Java Code: package ABC; import java.util.ArrayList; import java.util.Scanner; public class GetInputFromUser { private ArrayList<String> name = new ArrayList<String>();
I need to return all the object name of one class in an array. I have a class named country, and other classes with athletes and medals etc. I need to do a method that list an array with all the countries that participate, so all the objects created with the class country (i.e canada.country, usa.country, etc). Is there a way I can retrieve them?
I need to return all the object name of one class in an array. I have a class named country, and other classes with athletes and medals etc. I need to do a method that list an array with all the countries that participate, so all the objects created with the class country (i.e canada.country, usa.country, etc). Is there a way I can retrieve them?
I need to design a class named Location for locating a maximal value and its location in a two-dimensional array. The class should contain public data fields row, column, and maxValue that store the maximal value and its indices in a two dimensional array with row and column as int type and maxValue as double type.
I need to write the following method that returns the location of the largest element in a two-dimensional array: public static location locateLargest(double[][] a)
The return value is an instance of Location. Write a test program that prompts the user to enter a two-dimensional array and displays the location of the largest element in the array.
Here is what i get when I run
Enter the number of rows and columns of the array: 3 4 Enter the array: 23.5 35 2 10 4.5 3 45 3.5 35 44 5.5 9.6 The location of the largest element is at 00 The location of the largest element is at 01
But I need it to display this instead.
Enter the number of rows and columns of the array: 3 4 Enter the array: 23.5 35 2 10 4.5 3 45 3.5 35 44 5.5 9.6 The location of the largest element is 45 at (1,2)
public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Number of rows and columns: "); int row = input.nextInt(); int col = input.nextInt();
[Code] ....
Enter the number of rows and columns of the array: 3 4 Enter the array: 23.5 35 2 10 4.5 3 45 3.5 35 44 5.5 9.6 The location of the largest element is at 00 The location of the largest element is at 01
I need it to display this instead.
Enter the number of rows and columns of the array: 3 4 Enter the array: 23.5 35 2 10 4.5 3 45 3.5 35 44 5.5 9.6 The location of the largest element is 45 at (1,2)
I am trying to understand the following code.This return statement should actually return the char at myArray[index] first, then increments the index afterwords correct?
I have attempted on my own many times but I am not getting any closer to a solution.
/**
* Returns a SmartArray with eight values. The values are the values stored in the 8 neighbors of the array cell at the given location in the Smart2DArray.
* Start with the neighbor to the "north" of the given cell and proceed clockwise, using -1 as the value if the neighboring cell is outside the Smart2DArray.
For example, if the array is: 1 2 3 4 5 6 7 8 9
neighbors(1, 1) should return a SmartArray with the values: 2 3 6 9 8 7 4 1 in that order.
neighbors(2,1) should return a SmartArray with the values: 3 -1 -1 -1 9 8 5 2 in that order.
*/ public SmartArray neighbors (int col, int row) { }
I am having an issue with a parallel array that I created that returns array values based on an input. The code only works for the first four array locations just fine. The remaining values are not found. I thought it might be a memory allocation issue with the array size, I tried to dimension the array, however, using the Eclipse editor get errors.
import java.util.*; import javax.swing.JOptionPane; public class StudentIDArray { static String[] studentNum = new String[] {"1234", "2345", "3456", "4567", "5678", "6789", "7890", "8901", "9012", "0123"}; static String[] studentName = new String[]
I'm trying to return an array back to main. The array returned to main should contain the reversed random numbers array. I believe I have the array correctly reversed within the 'reverseArray' method. I'm trying to send this array back to main, but it appears to contain empty data (a bunch of zeros).
Java Code:
class ArrToMain { public static void main(String[] args) { final int NUMBER_OF_ELEMENTS = 1000; double[] numbers = new double [NUMBER_OF_ELEMENTS]; //Invoke initialize method initialize(numbers);
Assignment: Given an array of scores sorted in increasing order, return true if the array contains 3 adjacent scores that differ from each other by at most 2, such as with {3, 4, 5} or {3, 5, 5}.
public boolean scoresClump(int[] scores) { for (int i = 0; i < scores.length; i++) { int a = scores[i]; int b = scores[i + 1]; int c = scores[i + 2]; if (Math.abs(b-a) + Math.abs (c-b) <=2) return true; } return false; }
I got it right for some of the input, but not one of them. I tried to use the for loop and if statement on a specific input that I got wrong:
I suspect it has something to do with the for loop, but I don't see the problem with it. It should work, shouldn't it? But anyway, here is the error for {4,5,8} :
Question - Given an specific integer and an array of integers, find and remove all occurrences of the given integer and return an amended array. I solved it. Here is my solution -
I have problems getting the right number of times for each number of the array. Here is my code:
public static void main(String[] args) { int[] a = { 3, 13, 5, 9, 13, 6, 9, 13, 2, 3 }; int num = 3; int count = numbers(a, num); for (int i = 0; i < a.length; i++) {
1. Create a program that will return the maximum and minimum numbers in the elements of ONE-dimensional integer array. Save it as MaxMin_OneDim.java
2. Create a program that will return the maximum and minimum numbers in the elements of each row in a TWO-dimensional integer array. Save it as MaxMin_TwoDim.java
3. Write a program PrintPattern which prompt a user to enter a number and prints the following patterns using nested loops (assumed user entered number is 8 output is:)
1 .... 87654321
12 .... 7654321
123 .... 654321
1234 .... 54321
12345 .... 4321
123456 .... 321
1234567 .... 21
12345678 .... 1
(Without the dots, i just put them to give spaces)
I have to fetch only the book name attribute and use it for display .However say for example ,I have got the list of Books ie(C#,Oracle,Archius) ,passing this value to a method should return me an array of URL nodes value within it.
The idea is to display the book names in a list and then on user selection , corresponding URL needs to be fetched.
Was able to get the loop for traversing the nodes
[java=code] NodeList nodeList = document.getDocumentElement().getElementsByTagName ("Book"); for (int i = 0; i < nodeList.getLength(); i++) {... [java=code]
So
a) Display the BookNames
b) Get the corresponding URL's for the particular book if I pass the Bookname