Sorting From Lowest To Highest

Feb 23, 2014

I'm very new to Java and ran into a problem. My results are not in order and I'm not sure what I'm doing wrong.

My results come out like this instead of being in order from lowest to highest: "77 99 44 55 22 88 11 0 66 33"

Here's what I have:

class ArrayIns {
private long[] a; // ref to array a
private int nElems; // number of data items
//--------------------------------------------------------------
public ArrayIns(int max) // constructor
{
a = new long[max]; // create the array
nElems = 0; // no items yet

[Code] .....

View Replies


ADVERTISEMENT

Printing Highest And Lowest Of Three Numbers Using Java?

Feb 23, 2014

I am working on an assignment but I am not getting any out put and I couldn't fix it?The class HighLow below asks for three integers and prints the highest and lowest of them on screen. Your task is to write the missing methods high and low, which receives the integers user inputs as parameters and return the highest and lowest integers respectively.

import java.util.Scanner;
public class HighLow {
public static void main(String[] args) {
int number1, number 2, number 3, high, low;
Scanner reader = new Scanner(System.in);

[code]......

View Replies View Related

Printing Highest And Lowest Of Three Numbers Using Java

Feb 23, 2014

The class HighLow below asks for three integers and prints the highest and lowest of them on screen. Your task is to write the missing methods high and low, which receives the integers user inputs as parameters and return the highest and lowest integers respectively.

import java.util.Scanner;
public class HighLow {
public static void main(String[] args) {
int number1, number 2, number 3, high, low;
Scanner reader = new Scanner(System.in);

[code]....

View Replies View Related

Display All Student With Their Grade Sorted From Highest To Lowest

Oct 22, 2014

Write a program that promts a professor to input grades for five different courses for 10 students. Prompt the professor to enter only A,B,C,D, or F for grades(A is the highest grade, F fail). use variables for student number(1 through 10) and grade numbers(1 through 5). create a menu for Search. if the user select search it will prompt a letter correspond to grade. display all student with selected grade. if the user just enter nothing, display all student with their grade sorted from highest to lowest.

View Replies View Related

Reading Lowest / Highest / Average Grades And Reporting Them From For Loops?

May 3, 2014

import java.util.*;
import java.text.*;
public class Quiz {
public static void main(String[] args){
Scanner s= new Scanner(System.in);
int quests = 0;
String input ="";

[code]....

I'm not getting any errors anymore.

View Replies View Related

Java Program - Find Next Highest Or Lowest Prime Number

May 2, 2014

Java program takes positive int from user and determine if prime. Next the program finds next highest or next lowest prime number.

import java.io.*;
import java.util.*;
public class pa2take2 {
public static void main (String[]args){
int menus; //menu selection

[Code] ......

View Replies View Related

Write A JAVA Program That Will Input 10 Scores And Output Highest And Lowest Score

Jan 9, 2015

1.Write a JAVA program that will input 10 scores and output the Highest and Lowest score.

2.Write a JAVA program that will input the base and power and display the result: Example: Base is 4 Power is 2 the answer is 16 (Note: Math.pow( ) method is not allowed)

3.Write a JAVA program that will input an integer number, and then will output the sum of all inputted numbers. The program will stop in accepting inputs if the user entered 0.

View Replies View Related

Calling Methods For Java GradeBook - Calculate Highest And Lowest Grades In Array

Apr 15, 2015

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;

[Code] ....

View Replies View Related

Display Lowest And Then Next Lowest Number From Array

Jan 5, 2015

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 +".");
}

View Replies View Related

Checking If Int Is Lowest Out Of 4?

Apr 30, 2014

I'm trying to find the int with the lowest value, and I only know how to set it up like this:

Let's say x1 is the lowest.

int x1, x2, x3, x4;
 
if (x1 < x2 && x1 < x3 && x1 < x4) System.put.println("x1 is the lowest value out of those 4");

Is there a way to shorten this at all? (It's alright if there isn't, just looking for shortcuts)

View Replies View Related

Calculate Lowest Value Of Array

Feb 13, 2015

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.

View Replies View Related

Find The Lowest Number?

Apr 12, 2014

I have to find the average, highest, and lowest numbers in an array. I already have the average and highest, and I thought I could find the lowest number the same way I found the highest, but it's not working. It just keeps coming out to 0. I've tried out different ways, but I want to see if there are better ways than doing MAX_VALUE for the lowest, then looping it through.

import java.util.Scanner; 
public class Test_Scores {
public static void main(String[] args) {
//array,scanner,values

[Code].....

View Replies View Related

How To Return 2 Lowest Scores

Mar 19, 2015

If this method returns the lowest score, how do I return the 2 lowest scores.

For example If I input 1, 2, 3, 4, 5 this code will return 1.

How do i return the two lowest scores, for example if I input 1, 2, 3, 4, 5, I want to return 1, 2

public double getLowestScore() {
smallest = testScores[0];
double sum = 0.0;
double total = 0.0;
double Average = 0.0;

[Code] ....

View Replies View Related

Return Lowest Value From Array

Aug 12, 2014

I am trying to return the lowest value from the array. having trouble trying to capture the return value by placing it into the variable ..

int myLowest = getLowest(yourNumbers); and then printing out myLowest

import java.util.*;
public class numArrays
{
public static void main(String[] args){
int numbers;
int[]yourNumbers;

[code]....

View Replies View Related

Finding Lowest Value In Array Using Linear Search?

Apr 5, 2014

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].....

View Replies View Related

Highest Of Three Grades

Sep 14, 2014

So I have created this program but I am having a couple of small problems with it. The first problem is that the user inputted numbers should all be on the same line. I have spent hours trying to figure this out and I have looked online but I've had no luck. The second problem is that the "lowest score" should be 42 and not 42.0. I don't understand how to make it so the number is an integer. I have posted the output that i'm getting and the way the output should look like at the bottom.

import java.util.Scanner;
public class Random
{
public static void main(String [ ] args) {
Scanner input = new Scanner(System.in);
double a, b, c;

[Code] .....

This is the output that i'm getting.

Enter three scores: 87
42
94

The average is: 74.33333333333333
The lowest score was: 42.0
The average without the lowest score is: 90.5
The grade is: A

This is the way the output should look like.

Enter three scores: 87 42 94

The average is: 74.33333333333333
The lowest score was: 42
The average without the lowest score is: 90.5
The grade is: A

View Replies View Related

Recursion Method With 2d Array To Find A Column With Lowest Sum

Jan 28, 2015

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 .

View Replies View Related

Unable To Pull Out Lowest Week Number In Program

Apr 29, 2014

This program reads off of a text file that I have attached to my post. It is supposed to:

display the total sales for each week
the average daily sales for each week
the total sales for all of the weeks
the average weekly sales
the week number that had the highest amount of sales
the week number that had the lowest amount of sales

I can get everything but the very last one. In my code you will see that I tried to use a really large number so it would pull out the lowest amount, but it still didn't work: low = 100000000;

 SalesData.txt (173bytes)
Number of downloads: 29
import javax.swing.JOptionPane;
import java.io.*;
import java.text.DecimalFormat;
import java.util.Scanner;

[code]....

View Replies View Related

How To Get Highest Value Of Array Of Integers

Jul 1, 2014

I am trying to write a method that returns the busiest hour in a logAnalyzer class that read web server data and analyze hourly access patterns and stores them in an array. My problem is, in order to get the busiest hour, I need to go through the hourCounts array to find the element with the biggest count.

View Replies View Related

Highest Value In Array List?

Feb 2, 2015

I have 3 classes Pet, Cat and Dog classes. Cat and Dog classes are childs of Pet class.

Each pet has the properties of

private String myName;
private int myX;
private int myY;
private int mySpeed;
private int myAge;

I have an array list which creates 100 dogs. How can I print out the dogs with the two highest age values?

View Replies View Related

Read Information From File - How To Get Highest Value

Nov 12, 2014

The requirement asked me to write a Java program to read information from the file, display the original information along with the player's average score of the season (one line for each player), and announce who is the highest average-scoring player of the team. But I always only get the highest which show the last player.

Such like the output showed:

Smith 13.0 19.0 8.0 12.0 Player's average: 13.00
Badgley 5.0 Player's average: 5.00
Burch 15.0 18.0 16.0 Player's average: 16.33
Watson Player's average: 16.33
Knox 10.0 12.0 8.0 6.0 Player's average: 9.00
Casler 15.0 7.0 Player's average: 11.00
Winorburg 13.0 14.0 14.0 23.0 20.0 Player's average: 16.80
Morton 4.0 11.0 13.0 Player's average: 9.33
Seeling 16.0 8.0 9.0 11.0 Player's average: 11.00
Tanshi 5.0 13.0 10.0 Player's average: 9.33

The highest average-scoring player is: Tanshi

import java.util.Scanner;
import java.io.*;
public class PA7{
public static void main(String[] args) throws IOException{
String name = null;

[Code] .......

View Replies View Related

Find Highest Rated Movie

Apr 17, 2014

import java.io.*;
import java.util.*;
import java.util.StringTokenizer;
class read {
public static void main(String[]args) {
populateFilmVector();
bestfilm();

[Code] .....

There are my two java files I want to search through film items and find the one with highest rating ...

Film title ain & Gain
Lead role wayne Jhonson
Run time :123
Rating :4.5
id :23415

[Code] .....

That is my output. I want this to be output along with which ever one has the highest rating....

View Replies View Related

How To Make A Method That Find Highest Value In Array

Dec 5, 2014

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

[code].....

View Replies View Related

Comparing Elements In Array To Find Highest Int

Sep 3, 2014

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);

[code]....

View Replies View Related

Print Only Top 15 Highest Numbers Of Occurrence From RNG Output

Oct 15, 2014

I created a random number generator for my course and it works perfectly. I now need to print only the top 15 highest numbers of occurrence from the RNG output. How i can do this?

Here is my block of code.

package section4;
import java.util.Random;
public class Lottery {
public static void main(String[] args) {
Random rand = new Random();
int freq[] = new int[51];

[Code] ....

View Replies View Related

Find The Column With Highest Average Number

Feb 14, 2015

code a 10 * 10 matrix, with random numbers from 1 to 100,

i) Find the most repeated number.
ii) Use the Binary Sort, to sort the matrix in ascending order.
iii) Find the Column, with the highest average number.

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved