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
ADVERTISEMENT
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
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
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
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
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
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
View Related
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
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
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
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
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
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
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
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
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
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
Oct 25, 2014
//checks wether an int is prime or not
public static void main(String[] args) {
int n = 17;
boolean prime = true;
if (!(n==2)) {
for (int i = 2; i * i <= n; i++) {
if (n % i == 0);
[Code] .....
View Replies
View Related
Apr 15, 2015
Suppose i have a string which has certain file names, S = "a.png, b.gif, c.xlsx, d.docx, e.xlsx, f.gif";I need to check if the string has more than one .xlsx file names,
View Replies
View Related
Jan 12, 2015
I just can't find a way to check if user puts any input or not? The line is Employee Name and I need to validate that he puts something there.
import java.util.Scanner;
public class JavaMartInventorySystem {
public static void main(String[] args) {
String empName;
Scanner keyboard = new Scanner(System.in);
[Code] ....
View Replies
View Related
Feb 10, 2014
I want get a specific document from data set if a given string matches in that document.
If given string is 'what is java' and,
doc1='... what is full form of java ...'
doc2='... is java what ...'
doc3='... what is java ...'
then the output should contains doc1, and doc3.
I'm trying like this.
for(String key_word: key.split("W+")) {
for (String _word : line1.split("W+")) {
if(word.toLowerCase().equals(key_word.toLowerCase())) {
key_final=key_final+" "+key_word;
}
}
}
I'm getting wrong output containing doc1, doc2 and doc3.But I want only the exact match. Here each document is containing some paragraphs.
View Replies
View Related
Nov 21, 2014
I have a programming assignment in which I have to make a program which loads a crossword from a Properties file and then, when the user press a button, the program checks if the letters the user has typed in the interface are the same as in the correct matrix. If all the letters from a word are correct, the program must paint every letter of the word green.
I'm using two matrix, one that is called "mundo" (I 'm from Latin America) , which has the correct letter for each box. The other one is a JtextField matrix which ='ve created using a Gridllayout. I called this one crucigrama (crossword in Spanish)
This is the code I wrote to validate: So you can understand, here is a translation:
numero = number
fila = row
column = columna
bien - a boolean I used to check if the letter I've checked before are the same as the correct ones
.darLetra() - returns a string with the correct letter
[Code] .....
View Replies
View Related
Sep 28, 2014
which method i can use so that the program checks if the input value is a digit or else outputs a message saying that `the value entered is not a number.
View Replies
View Related
Feb 10, 2015
I'm trying to write code for a program that checks numbers upto a number that the user gives. I've looked around, and the nearest matches I can see are people using for loops with predetermined amounts of looping.The only real tools I'm allowed to use are basic arithmetic, and while loops. The program is supposed to have 2 nested while loops.
import java.util.Scanner;
import java.io.*;
public class questionTwo234234 {
public static void main(String[] args){
[code]...
View Replies
View Related
Jan 18, 2014
I have the following code to check for five characters palindrome but it always give me incorrect answer that if i have a word like radar the answer it isn't a palindrome. and if i changed any thing in the code i got either stack overflow or index out of bounds exception
The code is as the following
import java.util.Scanner;
public class Palindrome {
int first =0;
static int n;
int last = 4;
int y = 0;
public static void main(String [] args)
[Code] .....
View Replies
View Related
Aug 5, 2014
I'm up to an app which includes Alarm clock in it. User selects the date using JSpinners and My Alarm clock class checks if the current date is equal to the selected date and pops up an alarm. That's all i've done so far. What i want is some ideas about how can i manage these alarms in my app. What i think is:
* Getting alarm dates from user and save it in database and creating a thread which runs always and check database whether there is an alarm... (will it make my app) ??
In simple words how to continuously check for upcoming alarms and popup any time any alarm comes up during my app is running
Note: My App is not only about alarms, it also contains a complete management system.
View Replies
View Related