Input 10 Integer Numbers Into Array And Determine Maximum Value Entered

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


ADVERTISEMENT

Return Maximum And Minimum Numbers In Elements Of Integer Array

Oct 21, 2014

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)

View Replies View Related

Loop That Calculates Maximum / Minimum And Average Of 10 Input Numbers?

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

Array Is A Set Of Numbers In Triangle - Find Maximum Path

Aug 12, 2014

If you aren't familiar with the euler problem 67, you are given an array that is a set of numbers in a triangle. Like this

3
7 4
2 4 6
8 5 9 3

and you have to find the maximum path, which for this one is

(3)
(7) 4
2 (4) 6
8 5 (9) 3

I have solved this problem iteratively with the code below

depth = depth-2;
while (depth >=0) {
for (int j = 0; j <= depth; j++) {
values[depth][j] += Math.max(values[depth+1][j], values[depth+1][j+1]);
}
depth -= 1;
}

depth is a variable for the row in the triangle. My problem is that i need the solution to be recursive and i am having trouble doing this. So far i have

public static int findMax(int[][] array,int depth) {
if (depth==0)
return array[0][0];
else if
}

View Replies View Related

Ask User To Store 10 Numbers In Array - Print In Order Entered And Reverse

Apr 15, 2014

Write a Java program that asks the user to store 10 numbers in an array. You should then print the array in the order entered and then print in reverse order. However, instead of putting all the information in the main, you should use a class called PrintIt. The PrintIt class should have an instance variable that is an array to hold the numbers. You should have a method that will print the array in the order entered. You will also need a method to print in reverse oder. Then create a tester class that asks the user to enter 10 numbers and puts them in an array.

So far I've got this.

public class printIt {
int i;
int [] numArr = new int [10];
public printIt () {
i = -1;

[Code] .....

Output:

Enter a number:

8
34

Forward:

8
34

Reverse:

34
8

end

what i want as an number is being able to print out 10 numbers but this only lets me do two numbers. Why is that so?

View Replies View Related

Simple For Loop - Determine Factorial Of A Number Entered By User

Jun 28, 2014

I'm trying to learn Java and my current project is to write a short program to determine the factorial of a number entered by the user. I haven't looked. There may be a method that will do it, but I want to use a for loop specifically.

What I have compiles just fine. I'm actually pretty thrilled just with that. Here is what I have:

class factorial {
public static void main( String[] args) {
Scanner scan = new Scanner(System.in );
int num;
int product = 1;

[Code] ....

View Replies View Related

Input 10 Integer Elements In Array And Sort Them In Descending Order

Jun 13, 2014

How to input 10 integer elements in an array & sort them in desc. order using the bubble sort technique.

View Replies View Related

Find Maximum Between Three Numbers Using Ternary Operator?

Aug 23, 2014

Write a program to find maximum between three numbers using ternary operator.

View Replies View Related

List All Prime Numbers Between Two Entered Numbers

Oct 17, 2014

Program is to list all prime numbers between two entered numbers.

import java.util.Scanner;
public class question6 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter lower int:");
int x = input.nextInt();

[Code] .....

View Replies View Related

Nested For Loops - Determine If Inputted Integer Is Even Or Odd

Sep 29, 2014

So I cant figure out why my output for my for loop isn't working properly. So the output for the square comes out right but the for loop isn't working properly for the H. I have tried to figure it out and it should go to the next line but its not.

import java.util.Scanner;
public class Random
{
public static void main(String [ ] args)
{

[Code] ....

Output

Enter a positive odd integer: 5

Square:
*****
* *
* *
* *
*****

H:
* *

View Replies View Related

Pair Of Two Numbers - Return Average / Distance / Maximum And Minimum Value

Sep 27, 2013

I have been having difficulty with the weeks concepts in my online Java class, the program is to be as followed:

For this exercise you will implement a class called Pair, that represents a pair of two numbers.The Pair class should include the following constructor and methods:

CONSTRUCTORS
public Pair(double num1, double num2) -- Creates an object that represents a pair of double values

METHODS

public double getAverage() -- Returns the average value of the two numbers
public double getDistance() -- Returns the absolute vale of the distance between the two numbers
public double getMaximum() -- Returns the maximum value of the two numbers
public double getMinimum() -- Returns the minimum vale of the two numbers

Write a class called PairTest that tests your Pair implementation. The PairTest should prompt the user for the two values, create a Pair object with the values and then print the average, distance, maximum, and minimum of the pair. The input / output should look like the following:

Enter the first number: 5.5
Enter the second number: 3.0

Average: 4.25
Distance: 2.5
Maximum: 5.5
Minimum: 3.0

NOTE: For this exercise, your solution should not use any conditional statements. Instead you should use the methods provided by thejava.util.Math.

So far I have:

import java.lang.Math;
import java.util.Scanner;
public class Main
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
{
System.out.println("Please enter a value for the first number");

[Code] ....

View Replies View Related

Filters Java Programming - Determine If Integer Is Not Divisible By Some Value

Apr 10, 2014

I am new to java and do not understand how to use filters very well. I need to write a code that determines if an integer is not divisible by some value. A filter also contains an upstream filter so that this filter can be part of a chain of filters.

View Replies View Related

Web Services :: GET Or POST - Determine If Passed In Integer Is Prime Or Not

Jan 27, 2015

I have an endpoint that will determine if a passed in integer is prime or not. Should the request to this endpoint be GET or POST? Right now, I'm thinking it should be GET since it doesn't do anything to any resource.

View Replies View Related

Lotto Game - Receive Integer And Check If Int Was Not Entered Before

Nov 29, 2014

We were given the assignment to program a lotto game. in our game we should do follow the following steps below, and we are supposed to use atleast tree methods. the first one to receive the array of integers and an integer and check if the int was not entered before. the user should not repeat the same number. the other method will draw all numbers of a game (quantity of numbers to draw is based on the number parameter) and returns them in an array. the last method will display the result of the game. It receives a list of all lines played and a list of all numbers draw.

these are the steps to follow:

1. Ask the user how many lines (games) the user would like to play. Each line is made of five numbers between 1 and 45 (inclusive).

2. Ask the user to enter five numbers between 1 and 45 (inclusive) for each line. The user must NOT be allowed to enter a number more than once for each line.

3. When all the numbers for all the lines are entered, the program should display all lines and asks the user to confirm the game. If the user does NOT confirm the game, the program should start all over again.

4. Draw (generate) five numbers between 1 and 45 (inclusive). The numbers should be unique within the draw.

5. Draw (generate) one number (the bonus number) between 1 and 45 (inclusive). The number should be unique within the draw.

6. Display all the lines played and the result of each line.

7. Ask the user if the person would like to play again, if so the program should start the process all over again.

View Replies View Related

Read Integer From Keyboard Until Negative Number Is Entered

Apr 8, 2014

Basically i have a question ask me to write a program that read integer from keyboard until a negative number is entered, and then print out the max and min out of the number i have entered.

This is what i have done already which works, but i need to ignore the negative number when print out max and min...which i dont know how to do so. when i compile this program now it will always give me the negative number i enter at the end as minimum. which i need to ignore

Also if negative number is entered at once the program should print a error message say max and min are undefined.

public static void main(String[] args) {

Scanner in = new Scanner(System.in);
int large = Integer.MIN_VALUE;
int small = Integer.MAX_VALUE;
while(true) {
System.out.print("Enter a integer: ");
int n = in.nextInt();

[Code] ....

View Replies View Related

Print Maximum And Minimum Values Of Integers From User Input

Apr 27, 2015

So I'm learning java from a website and I was tasked with creating a simple program which allows the user to enter a series of integers, then finally when they decide to input a non-integer the program will print the maximum and minimum values of the integers they entered. So for example if they entered 5, 4, 3 and 2 then enter a non-integer the program would output 5 (maximum value), then 2 on a new line (minimum value).

Here is my code:

import java.util.Scanner;
public class MaxMinPrinter {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int max = Integer.MIN_VALUE;
int min = Integer.MAX_VALUE;

[Code] ....

And this is what the output looks like:

Actual output
-------------------------------------------
Enter an integer: 5
- 10
-
- Enter an integer: -4
- 8
- -6
-
- Enter an integer: 11
- -1
-
- Enter an integer: q
- -1
- -6

When it's supposed to look like this:

Expected output
-------------------------------------------
Enter an integer: 5
Enter an integer: 10
Enter an integer: -4
Enter an integer: 8
Enter an integer: -6
Enter an integer: 11
Enter an integer: -1
Enter an integer: q
11
-6

View Replies View Related

User To Input 10 Numbers - Find Smallest Element In Array

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

Reversing Numbers Entered (in Java)

Mar 29, 2014

How to calculate the minimum and the maximum in the same program.
 
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
int integers;
int[] numbers;
numbers = new int[10];
int max;
int min;
 
[Code] ....

My result when I input numbers are always the following:

"Numbers in reverse order are: 9, Numbers in reverse order are: 8,
Numbers in reverse order are: 7, Numbers in reverse order are: 6
Numbers in reverse order are: 5, Numbers in reverse order are: 4,
Numbers in reverse order are: 3, Numbers in reverse order are: 2,
Numbers in reverse order are: 1, Numbers in reverse order are: 0."

View Replies View Related

Swing/AWT/SWT :: GUI To Add A List Of Numbers Entered By The User

May 9, 2014

I have a GUI with a textArea for the user to input numbers, a button which should "listen" for those numbers, and then a textField to display the sum. I have my code working for user input of one number; but I'm at a loss as to what sort of loop I need to create to get it to read each line of input. I wasn't sure whether to put this in the beginner forum or here, because I am definitely a beginner.

So my code thus far that works with one input:

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

[Code] ....

View Replies View Related

How To Find Maximum Element Of Each Column In 2D Array

Oct 26, 2014

import java.io.IOException;
public class Largestcolumn
{
public static void main ( String[] args ) throws IOException
{
int largest = 0;
int newnumber = 0;
int[][] data = { {3, 2, 5},

[Code] ....

When I run this code, I get this following output: The largest element in column 0 is: 9.
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4
at largestcolumn.Largestcolumn.main(Largestcolumn.java:27)
Java Result: 1

It outputs the first column's maximum element but then throws an out of bounds error. I'm new to Java and I can't figure out how to fix my code so that it will work for this multidimensional array and output the maximum elements in all of the columns.

View Replies View Related

Math On Three Numbers - Get Average / Sum And Number Entered By User

Feb 25, 2015

Java program : For this assignment you are going to write code for the following class:

MathOnThreeNumbers

Here are the specifications of class MathOnThreeNumbers:

Methods of class MathOnThreeNumbers:

1. inputThreeNumbers
2. getAverage
3. getSum
4. getNumberOne
5. getNumberTwo
6. getNumberThree

Constructor of class MathOnThreeNumbers

write a constructor that initializes the first, second, and three numbers to 1, 2, and 3 respectively.

Specs for the methods methods:

1.
name: inputThreeNumbers
accessibilty: public
arguments: none
what it does: asks the user for three numbers of type double

2.
name: getAverage
accessibilty: public
arguments: none
what it does: returns average of the three numbers

3.
name: getSum
accessibilty: public
arguments: none
what it does: returns sum of the three numbers

4.
name: getNumberOne
accessibilty: public
arguments: none
what it does: returns the first number entered by the user

5.
name: getNumberTwo
accessibilty: public
arguments: none
what it does: returns the second number entered by the user

6.
name: getNumberThree
accessibilty: public
arguments: none
what it does: returns the third number entered by the user

Here is an example of how the class MathOnThreeNumbers works. The following code produces the output displayed after the code.

MathOnThreeNumbers mm = new MathOnThreeNumbers();
System.out.println("first: " + mm.getNumberOne());
System.out.println("second: " + mm.getNumberTwo());
System.out.println("third: " + mm.getNumberThree());
mm.inputThreeNumbers();

[Code] .....

View Replies View Related

Program To Pull Prime Numbers Between Two Entered Values

Oct 18, 2014

Program to pull prime numbers between two entered values,

import java.util.Scanner;
public class question6 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter lower int:");

[Code] ....

View Replies View Related

Perform Mathematical Calculation Between Two Numbers Entered By User

Feb 16, 2015

I need to write a Java program to perform a mathematical calculation between two numbers entered by the user. User has to choose the mathematical operation and input it and then when the user enters 2 numbers, he gets the answer. When user enters any other character other than *, /, + and - he should be able to exit. Perform calculation between numbers should be until user decided to exit from the program. My code is below, calculation part goes well, but can't get it exit when user enter any other character.. How to fix it?

import java.io.*; 
public class q11

public static void main(String[]args)throws IOException
{
InputStreamReader ISR=new InputStreamReader(System.in);
BufferedReader BR=new BufferedReader(ISR);
while(true){
System.out.println("Enter..");
System.out.println("* : For multiplication");

[Code]...

View Replies View Related

Checking If Any Input Has Been Entered

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

Create 2D Array Out Of CSV File And Find Number Of Elements To Determine Array Size

Mar 24, 2015

I am taking the Class Algorithms and Datastructures and got an assignment for Lab that really throws me off. The goal is to create an Array out of a given CSV file, implement several Methods that get the size of array, etc.

I am still stuck in the first part where the CSV has to be imported into the Array. My problem is that I need a mechanism that figures out the needed size for the Array, creates the array, and only then transfers the data from the CSV.

The list consists of the following wifi related values:

MAC-Adress, SSID, Timestamp, Signalstrength.

These are on the list, separated by comma. The Columns are each of these, and the rows are the four types of values making up the information on a certain wifi network.

The catch is, we are not allowed to use any of the following:

java.util.ArrayList
java.util.Arrays
and any class out of java.util.Collection.

So far I used the BufferedReader to read in the file and tried to implement the array, but I get an arrayindexoutofboundsexception.

Below is my Code (Its still an active construction zone):

public class WhatsThere {
public WhatsThere(String wifiscan) throws IOException {
}
public static void main(String[] args) throws IOException {
// WhatsThere Liste = new WhatsThere(String wifiscan);
String[][] arrayListe = new String[0][0];

[Code] ....

View Replies View Related

Determine If User Input Is Fibonacci Number Or Not

Oct 20, 2014

Part A: While Loop Program

Write a program that detects Fibonacci numbers. Prompt the user to input a positive integer. Upon input, the program will determine if the number is either a Fibonacci number or not. If a Fibonacci number, then the order of the number in the sequence must be output. If not a Fibonacci number, then the Fibonacci numbers above and below it (including their order in the sequence) must be output. Once it finishes, the program will prompt the user for a new number. The program will exit if the user enters a string (such as “quit”) instead of an integer. Use the sample output file, fib-seq-det.txt, to view a sample session

This is my project, I wrote a programs that tells you if the input number is a fibonacci number or not. For some reason it only works for some Fibonacci numbers but not all of them.

import java.util.Scanner;
public class While
{
public static void main(String[] args) {
System.out.println("Welcome to the Fibonacci Sequence Detector
");
Scanner in = new Scanner(System.in);
System.out.print("Please input a number for analysis: ");
int input = in.nextInt();

[Code] ....

View Replies View Related







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