Largest Of Input Numbers?
Nov 5, 2014
I think the problem in this is that the variable max is initialised as 0. Afterwards it remains in the while loop only, so the output is always 0. I dont know how to bring the last max value out of loop and print it.
import java.util.Scanner;
/**
*
* @author
* @version
*/
public class TEST1
[Code].....
View Replies
ADVERTISEMENT
Jul 10, 2014
I need to find the largest value in a scanned file.I've gotten the count, sum, average, evens, and odds myself.The code above the while loop is not mine and my professor said I may no edit it or other wise mess with it. I also may not use arrays.Also I've realized that the largest/smallest are recording the value of count. I've tried the following:
Scanner infile = new Scanner ( new FileReader(args[0]) );
int count=0,sum=0, largest=Integer.MIN_VALUE,smallest=Integer.MAX_VALUE, evens=0, odds=0;
double average=0.0;
[code]....
View Replies
View Related
Jan 13, 2015
how can i make a program that declare the largest and smallest out of three numbers??
/*
* To change this license header, choose License Headers in Project Properties.
int a;
int b;
int c;
[Code]....
View Replies
View Related
Feb 5, 2014
I am trying to find 3 largest numbers in an array using a single For loop but my following code is still showing randomly sorted numbers.
public class largest3 {
static int m, n, o;
static int array[] = new int[100];
public static void main(String[] args) {
for (int i = 0; i < 10; i++) {
array[i] = (int) (Math.random() * 100);
[Code] ....
View Replies
View Related
Apr 15, 2014
I have to get the user to enter in 10 numbers and with those 10 numbers I have to find the total, average, smallest, largest numbers in the set the user inputs. I have the total and average already figured out but how would you go about trying to find the largest and smallest numbers within this set of code.
import java.util.*;
public class testhw7
{
public static void main (String [] args) {
Scannernumberin = new Scanner (System.in);
doublevalue[];
doubletotal;
[Code]...
View Replies
View Related
Jan 25, 2014
How to create a simple program that can input number from 1 to n. and display the numbers which input by the user and also display the sum and average of it.
Ex.
Please input a number:
1 2 3 4 5 6 7 8 9 10
the sum numbers of 12345678910 is 55
the average number of 12345678910 is ______,
View Replies
View Related
Feb 20, 2014
I am very new to Java. I have been working for a couple months on a program for school. It has not gone well. I finally was able to scrap together a working program, but i left something out that needs to be. I have to include input validation to check for negative values, prompting users to re-enter values if negative. I have included my current code, the program works perfectly, but what to do about the negative numbers.
Java Code:
package gradplanner;
import java.util.Scanner;
public class GradPlanner {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int numofclasses = 0;
int totalCUs = 0;
[Code] ....
View Replies
View Related
Feb 20, 2014
I am very new to Java. I have been working on a program. It has not gone well. I finally was able to scrap together a working program, but i left something out that needs to be. I have to include input validation to check for negative values, prompting users to re-enter values if negative.I have included my current code, the program works perfectly, but what to do about the negative numbers.
package gradplanner;
import java.util.Scanner;
public class GradPlanner {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int numofclasses = 0;
[Code] ....
View Replies
View Related
Dec 11, 2014
I am writing a program to reverse a user inputted number (Example - 54321 is 12345) The code works great minus the fact that if I input a number that begins with zero, the output will drop the zero. Would it make more sense to just set this up using strings?
import java.util.*;
public class Week7_Programming_Problem
{
static Scanner console = new Scanner(System.in);
public static void main(String[] args)
{
int inputNum, outputNum;
[Code] ....
View Replies
View Related
Dec 4, 2014
Write a program to maintain a list of the high scores obtained in a game. The program should first ask the user how many scores they want to maintain and then repeatedly accept new scores from the user and should add the score to the list of high scores (in the appropriate position) if it is higher than any of the existing high scores. You must include the following functions:
-initialiseHighScores () which sets all high scores to zero.
-printHighScores() which prints the high scores in the format: “The high scores are 345, 300, 234”, for all exisiting high scores in the list (remember that sometimes it won’t be full).
-higherThan() which takes the high scores and a new score and returns whether the passed score is higher than any of those in the high score list.
-insertScore() which takes the current high score list and a new score and updates it by inserting the new score at the appropriate position in the list
View Replies
View Related
Sep 13, 2014
I'm trying to write a program that calculates the factorials of the numbers 1 through 10, based on user input... My problem is that I don't know how to address the possibility of the user entering something other than a number. When I test the following code by entering a letter, I get an Input Mismatch exception. I'd like to be able to inform the user that the entry is invalid, and ask for another response. Here is my program thus far:
Java Code:
import java.util.Scanner;
public class Factorial {
public static String entryString;
public static char entryChar;
public static Scanner input = new Scanner(System.in);
[Code] ....
View Replies
View Related
Apr 17, 2014
import java.util.*;
public class SumOfAllEvens {
public static void main (String[] args) {
Scanner s = new Scanner (System.in);
//for (int i=1; i<4; i++){
int usernumber;
[code]....
I'm supposed to use a for loop that runs until it reaches the number input by the user, but I'm not sure how to tell the program to add the user's number along with all of the even numbers in between the user input and 2.
View Replies
View Related
Sep 12, 2014
import java.util.Scanner;
public class main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int number;
System.out.println("Input a number");
[code]....
What i want to do is that if the number is greater than 50 to count until 100. else if the number is less than fifty to count for example from 36 to zero.
View Replies
View Related
Feb 26, 2014
It does not calculate the maximum, minimum or average of the 10 numbers that the user is prompted to input.
My code:
import java.util.Scanner;
public class moretest {
public static void main( String [ ] args ) {
int total = 0;
int number;
int minGrade = 101;
[code]...
View Replies
View Related
Feb 6, 2014
New to programming, and my teacher wants us to declare two variables : num1 and num2, and have the user input values, then run it through 2*num1 - num2.
Here is what I have so far, and I am lost and frustrated:
package hellowworld;
import java.util.Scanner;
public class definevariables {
static Scanner console = new Scanner(System.in);
public static void main(String[] args) {
int num1;
int num2;
[Code] ....
View Replies
View Related
Apr 22, 2015
a. Write a Java program to input 10 integer numbers into an array named fmax and determine the maximum value entered. Your program should contain only one loop, and the maximum should be determined as array element values are being input. (Hint: Set the maximum equal to the first array element, which should be input before the loop used to input the remaining array values.)
b. Repeat 1a, keeping track of both the maximum element in the array and the index number for the maximum. After displaying the numbers, display these two messages:
The maximum value is: _________
This is element number __________ in the list of numbers
Have your program display the correct values in place of the underlines in the messages.
c. Repeat 1b, but have your program locate the minimum value of the data entered.
I did parts a and b but for part see i just want to know if i did it correctly or not
import java.util.Scanner;
public class MinimumValueArray {
public static void main(String[] args) {
//Variable Declaration
Scanner keyboard = new Scanner(System.in);
int size = 10;
[Code] ,.....
When I run it i get this The minimum value is 0.0
The element that holds the value is 0 right away. is this right for the minimum or am i supposed to enter values and it will display the minimum value like in parts a and b wit the maximum? will the minimum just always be 0 or ?
View Replies
View Related
Dec 2, 2014
I am trying to write a code that asks the user to input ten numbers and then finds and displays the smallest number out of the ones given. I am supposed to implement arrays into the program to do this. But the problem I have run into is that when I compile the code in jgrasp, I am given several error messages and I am not quite sure what I have done wrong. I'm assuming it is either a syntax or a logical error on my part but reading over the code I do not understand what is causing these errors.
This is the most current draft of my code:
import java.util.Scanner;
public class Exercise7_9 {
public static void main(String[] args) {
double[] numbers = new double[10];
//Enter ten double numbers: Scanner(System.in)
java.util.Scanner input = new java.util.Scanner(System.in);
System.out.println("Please enter ten numbers: ");
[Code] ....
/* Sample Run:
Enter ten numbers: 1.9, 2.5, 3.7, 2, 1.5, 6, 3, 4, 5, 2
*/
And these are the exact error messages:
----jGRASP exec: javac -g Exercise7_9.java
Exercise7_9.java:35: error: '.class' expected
if (double m > list[i]) {
^
Exercise7_9.java:35: error: illegal start of expression
if (double m > list[i]) {
[Code] .....
View Replies
View Related
Apr 7, 2014
I have been assigned to write a program that has a user input random numbers then the program is to sort them in different ways. I have the coding for the different sorts but, I have an error saying that I am missing a return statement in the "Bubble" method. I am trying to return "arr[i]" in the "for loop" which gives me this error, and when I try to take the "return arr[i]" outside of the "for()" loop the error reads the it cannot locate variable "i".
import java.awt.* ;
import java.awt.event.*;
import javax.swing.*;
public class SwingSorts extends JFrame implements ActionListener
{
JRadioButton bubble;
JRadioButton selection;
[Code] .....
View Replies
View Related
Nov 4, 2014
I have been struggling with this program for weeks. This program is supposed to take a user's inputted odd number and then print out all prime numbers lower than that number.
public class PrimeNumber
{
Scanner scan = new Scanner(System.in);
int userNum;
String neg;
public void getUserNum()
[code]...
View Replies
View Related
Jul 21, 2014
This is my program
public static void main(String args[]) {
Scanner in=new Scanner(System.in);
System.out.println("Enter the Total Number of Integers:");
int totalInteger=in.nextByte();
long largest=0;
for(int i=1;i<=totalInteger;i++) {
System.out.println("Enter Integer-"+i+":");
[code]...
I want to get Index of that particular number in which Value is largest.
What I need to change in my program?
View Replies
View Related
Nov 15, 2014
I am trying to display Largest value and Smallest value in an array but when I execute I get Largest value as 0.
Following is the code:
package simpleArray;
import javax.swing.JOptionPane;
class ArrayInteractive {
static String ch = "Q";
static boolean flag = true;
static String a[];
[code]....
View Replies
View Related
Apr 1, 2014
Thought process : Sort the array and print the last 2 element of any given array.
Note /| Should not use any inbuilt Array.sort()
Java Code:
//Write a code to print the 2 largest numbers from the given Array {2,8,10,5,9}
package arrays;
public class biggest2numbers {
public static void main(String[] args) {
int[] A = {2,8,10,5,9};
//Declaring 2 variable
int Max1,
Max2;
[Code] .....
View Replies
View Related
Apr 9, 2015
Write a program that finds both the largest and smallest of several integers. T. For example, a program that determines the winner and loser of a sales contest would input the number of units sold by each salesperson. The salesperson who sells the most units wins the contest; the salesperson who sells the least units loses the contest. Write a pseudocode program, then a Java program that inputs a series of 10 integers and determines and prints the largest integer and the smallest integer. Your program should use at least the following four variables: counter, number , largest and smallest. After i run the code i just get the largest input without the smallest .
This is my code :
import java.util.Scanner; // program uses scanner
// main Class begins
public class Largest12
{
public static void main(String[] args) //main method begins
{
//Initial variables
int counter = 0; // initiate counter
int number=0 ;
[Code] ....
View Replies
View Related
Jan 20, 2015
I want to reverse grades that i have put using JOptionPane from largest to smallest and the corresponding names..
import javax.swing.*;
import java.util.Arrays;
public class ArrayUtils {
public static void main (String[]args){
String length = JOptionPane.showInputDialog("Number of students");
[code]....
View Replies
View Related
Jan 26, 2015
Write a Java method that returns the largest value of an array of doubles passed to the method as an argument.
Back into java wasn't sure how to do it for doubles did one in the main for integers and then added a method changed from int to double and now i'm lost as go why its not working.
package kickstarter9;
public class Kickstarter9 {
public static void main(String[] args){
double myList;
double[] myList = {6.0, 4.1, 2.4, 6.8, 1.9, 9.4, 2.8, 4.6, 9.3};
// find the largest value in the list
[Code]...
View Replies
View Related
Mar 24, 2014
I need to create a program that uses ArrayList to store integers the user inputs, then scan the array for the largest number. I would also like the user to be able to exit this loop if the number 0 is entered.
As you can see below, I'm not sure how to correctly exit the do-while loop. I found this on another forum, but it does not work.
Java Code:
import java.util.*;
public class array {
public static void main(String [] args){
ArrayList<Integer> list = new ArrayList<Integer>();
[Code] ....
View Replies
View Related