Finding Fifty Biggest Numbers In The Array?
Feb 12, 2014How to find fifty biggest numbers in the array?
View RepliesHow to find fifty biggest numbers in the array?
View RepliesSo, if you are a football/soccer fan, you know that in every FIFA World Cup you have 4 nations. From those 4, 2 will qualify to the Knockout stages.
Let's say, after all the group fixtures are played, the standings are as follows :
1. England - 6 points
2. Spain - 4 points
3. Brasil - 3 points
4. Germany - 1 point
I want to know how I can select ONLY England and Spain for the Knockout stage of the FIFA World Cup (The class I am working on).
I have problem with sorting my numbers from smallest to biggest and i need to not have repeating numbers, I am stuck. I tried using Arrays.sorts(lottery) but didn't work. and i don't know to but make the numbers not repeat in the same line.
package lottonumbers;
public class LottoNumbers {
public static void main(String[] args) {
int[] lottery = new int[6];
for (int numoftimes=0;numoftimes<5;numoftimes++){
[Code] ....
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];;
[code]..
I have been struggling to find out what to change to allow my code to find the GCF of two numbers. The instance variable in the class is num, so I need to find the GCF of a and num. It works for the example problem of 25 and 15, returning 5, however it will not work for other problems.
public int findGCD(int a)
{
int result = 0;
int newNum = num;
if ((a > num) && (a % num != 0))
[Code] .....
How do u find the binary of negative numbers? I already did it for positive numbers,?
View Replies View RelatedMy interest in Java leads me to try and print numbers from 1-100. The output should show all numbers from 1-100 and each number that is divisible by by 13 should be replaced with a string "Fuzzy".
public class Fuzzy {
public static void main (String[]args){
for(int i = 0; i < 100; i++)
if(i % 13==0)
System.out.print(i + "fuzzy");
}
}
I have assigned random numbers to an 2D array, and I had to write a method that prompts the user for a number between 100 and 200. If that number is in the array, it should return 1. If not, 0. It only stays 0 though, even when the number matches one of the numbers in the array.
public static int Findit(int[][] numbers, int guess) {
int Findit = numbers[0][0];
int i = 0;
int x = 0;
boolean found = false;
for(i=0;i<numbers.length;i++)
[Code] ....
My current problem is when im trying to choose case 2 and call markItemOnLoan i cant seem to find the title i want after i enter a few. I will include all of my code but i have mentioned what I am currently stuck on :
import java.util.Scanner;
public class Library {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
MediaItem mCall = new MediaItem();
Library call = new Library();// makes instance
[code]....
How to declare a 2 dimensional array of interger of size 10 by 10. and then set every element of the array to 3. After this I need to add up all the element in this array and return the value.
final int ROWS = 10;
final int COLS = 10;
int[][] foo = new int[ROWS][COLS];
for (int i = 0; i < ROWS; i++){
for(int j = 0; i< COLS; i++){
foo[i][j] = 3;
}
}
This is what i have done so far(not 100% if is correct..) but how to add up all the array.
I'm trying to find the median of a set of numbers inputted into an array and I wanted to know how I would pass the array to the median calculator after I use selection sort to organize the numbers.THIS IS THE CODE THAT ORGANIZES THE ARRAY:
public void selectionSort(double[] myArray) {
for (int i = 0; i < myArray.length - 1; i++)
{
int index = i;
for (int j = i + 1; j < myArray.length; j++)
if (myArray[j] < myArray[index])
[code]....
The code that finds the median will only work if the array being used is already organized. How do I pass the new sorted array to the code that finds the median?
I'm almost finished with my assignment, I'm just having one small issue. The goal of this assignment is to have a user input as many values they want(up to 10) into a list. I need to store those in an array then figure out the sum of the numbers, the average, the Largest value, and the smallest value. I get everything to print out correct so far except for the Smallest number, it is returning a 0 every time. Here is my code:
import java.util.Scanner;
public class SimpleList{
Scanner in = new Scanner(System.in);
final private static int ARRAY_LENGTH = 10;
private float[] List = new float[ARRAY_LENGTH];
private int count = 0;
[Code] ......
From a given array of positive and negative numbers, I have to find the longest SUB-Array which represents a Zig-Zag sequence...
A Zig-Zag sequence means that one number is possitive, the next one negative, the next one possitive, and so on and so on...
Like this: -1, 4, -5, 6, -9, 2, -9 etc....
So that means, if the array looks like this:
1, 4, -2, -5, 6, -9, 1, -4, 9, -8, 7, 4, -3
the longest sub-array which fulfills the requirement is (the part in bold):
1, 4, -2, -5, 6, -9, 1, -4, 9, -8, 7, 4, -3
and I only need it's length, which in this case is: 8
public class StuTest {
private static Scanner keyboard = new Scanner(System.in);
public static void main(String[] args){
int[][] testScores; // [students][tests]
String[] stuNames;
[Code] ....
The method I am having issues with is the "printStudentReport" method. I am trying to calculate the average of a randomly generated number of students and tests. For my "printTestReport" method, I have to calculate the average of the test by test number.
I have a 2D array that is of type int[][]. it is populated with 1's and 0's. I need to create a method that allows me to search from the top row finding a possible path to the bottom--the path is a path of connecting cells containing 1. I need to create an array that stores the cells that are needed to be searched. When the search carries out, for each cell stored it needs to check the cells to the left, right, below and above the current cell.
I also need to create a variable to store the current cell. I thought initially it would be an int but it can't be because it needs to hold the the index of the current cell. and any of the cells searched that are an immediate neighbour of the current cell are added to the storage array.
I have these instructions but I am having trouble converting into code
Finding a path through vegetation from the top row to the bottom row: The idea is we will start from a cell in the top row and advance below for as long as we can. Since we are still not done exploring a cell until we have explored ALL it’s vegetation neighbors, we will add the cell to an array of cellsToExplore and only come back to it if the current cell we are examining is fully explored. Here is pseudo-code of the algorithm !
• Create array cellsToExplore (what size should this array be?)!
• Create an integer count that stores the number of cells in cellsToExplore!
• Go through the top row and add ALL vegetation cells to cellsToExplore!
• Create a variable to store currentCell we are exploring and set it to null.!
• while count > 0 do!
- set currentCell to the last cell in cellsToExplore (last cell added to the array).!
- label currentCell as burning vegetation!
- If the currentCell is on the bottom row then we return true (we found the path).!
- if the cell below currentCell is vegetation then add the cell below to the cellsToExplore array.!
- else if cell to the right of currentCell is vegetation then add the cell to the right to cellsToExplore!
- else if cell to the left of currentCell is vegetation then add the cell to the left to cellsToExplore!
- else if cell above the currentCell is vegetation then add the cell above to cellsToExplore.!
- else remove the currentCell from the cellsToExplore (we are done with this cell). !
• Return false!
I'm trying to find a word in an array of char.....but I'm stuck. How to formulate the code to step through the array and pick out the word. This is what I have so far...
public static void searchAcross(String string, char[][] puzzle) {
// Gets the number of rows in the matrix
int rowLength = puzzle.length;
//Gets the number of columns in the matrix.
int colLength = puzzle[0].length;
[Code] ....
int[] a = new int[7];
a[0] = 0;
a[1] = 10;
a[2] = 256;
a[3] = 57;
a[4] = 33;
a[5] = -154;
a[6] = 168;
[code]....
What program needs to find is the most biggest number. It does the job, but another task of the program is to find the index of that number . The second loop should do just that, but for some reason, as the loop goes further, it passes through the if statement even though answer "a[i]" is not equal to "answer". The idea is that if a[i] and answer are equal, the "i" should represent the index number.
I am working on this project that wants me to write a program that inputs 20 numbers, each of which is between 10 and 100, inclusive. As each number is read, display it only if it is not a duplicate of a number already read. The only part I am confused about is how to go about checking for duplicate values that the user may enter. And IF the user does input a duplicate value, it should not be stored again.In addition, the value entered should be printed out after it is entered along side the value that have been previously entered by the user such as:
23
23 45
23 45 67
23 45 67 12
and so on.
I am still fairly new at java programming.
import java.util.*;
public class NumberArray
{
public static void main(String[] args) {
// declare an array with 5 elements
[code]....
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
[Code].....
How can I find out the simple moving average by just using the numbers stored in an array?
View Replies View RelatedI've just written a program that generates 100 numbers that range from 0 ~ 25 using arrays, the program calls another method that sorts the even numbers into a separate array and returns the array. I need it to display both arrays, however, when I run my program, the numbers of both arrays are mixed together, and I'm not sure how to separate them.
[ public class Array1
{
public static void main(String[] args)
{
int array [ ] = new int[100];
for (int i = 0; i < array.length; i++)
{
array[i] = (int) (Math.random() * 26);
[Code] .....
I have a problem where I have to create random integers from 1 to n + 1. When the array is displayed I have to find the missing integer from the values that are displayed and show that value. I have to use O(n^2) and O(n) operations. I have created this code so far but I cannot figure out how to make my values display n + 1. It is only displaying values 1, 2, 3, 4 and 5 in random order. I also cannot figure out how to find the missing value. I have created a boolean displayed statement but can't determine how to use it in this code.
=Java
import java.util.Random;
public class Task6
{
public static void main(String[] args)
{
int[] numbers = new int[7]; //create array of numbers
Random random = new Random();
boolean displayed = false; //boolean value to determine if number was displayed
[code]....
A java program to print 10 random numbers between 512 and 1024 and then finds the smallest and biggest numbers from the list using only one loop
class BSLab4d {
public static void main (String[] args){
int[] nums = new int[10];
int largest = nums[0];
int x = 0;
int smallest = nums[0];
int y = 0;
[code]....
One of our assignments this week was to make a program that when given a number it will return the biggest prime factor of that number. So for example if the program is given the number 15, the output is 3.
144 gives you 3 also.
17 gives you 17
21 gives you 7.
Anyways, after some time trying out various things and combining stuff i googled with my textbook I somehow stumbled upon a code that works. But I cannot for the life of me understand how it works. I think it has something to do with the inner loop and the outer loop. But I feel like i cant go on without understanding how it works.
Here is the code:
public class BiggestFactor {
public static void main( String[] args ) {
int N;
N = StdIn.readInt();
int n = N;
[Code] .....
The program should find the biggest corner, based on the number zero.
A zero becomes a corner when there's the same amount of zeros under it, and left to it.
The program should print a message saying what's the biggest corner size.
Corner size is the number of zeros inside it.
Java Code:
import java.util.*;
class Corners
{
static Scanner reader=new Scanner(System.in);
static final int N=25;
static int corners(int a, int b, int[][] m)
[Code] ....
That's the output:
Java Code:
The BOX:
1 0 0 1 1 1 0 1 0 1 0 0 1 0 0 0 1 0 0 0 0 0 1 1 1
1 0 1 0 1 0 0 1 0 0 0 1 0 1 1 1 0 1 0 0 0 1 1 1 0
0 1 1 1 1 1 0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 1 0 0 0
0 1 0 1 0 1 1 1 1 1 1 0 0 0 1 1 0 0 1 1 0 1 0 0 1
0 0 1 1 0 0 0 0 0 1 0 0 0 0 1 0 0 1 0 0 0 0 1 1 0
[Code] ....
I need to make a code that will ask the user for an array size and the numbers that go in the array. Then it must ask for a new size and copy the numbers from the first array and add numbers to fill the new array.
import java.util.Scanner;
import java.util.Arrays;
public class Lab07{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("How many numbers do you want to enter?");
[Code] ....
I can make the first array but I am getting stuck on the second this is what I am getting back
How many numbers do you want to enter?
3
Enter the 3.0 numbers now.
7
1.2
9
These are the numbers you have entered.
[7.0, 1.2, 9.0]
How many numbers do you want to enter?
5
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 3
at Lab07.resizeArray(Lab07.java:27)
at Lab07.main(Lab07.java:18)
how do I get the new array and not the error