ask user how many numbers to be inputted and determine the sum and highest number using an array in java

View Answers

January 16, 2012 at 12:41 PM

import java.util.*; class ArrayExample{ public static void main(String[] args) { int largest = 0; Scanner input = new Scanner(System.in); System.out.print("How many numbers you want to display: "); int n=input.nextInt(); System.out.println("Enter array values: "); int arr[] = new int[n]; int sum=0; for(int i = 0; i < arr.length; i++) { arr[i] = input.nextInt(); if (largest < arr[i]) { largest = arr[i]; } sum+=arr[i]; } System.out.println("Largest number is: " + largest); System.out.println("Sum of array values: " + sum); } }

January 17, 2012 at 8:57 AM

Thanks a lot for the code.... :) it helps me a lot.... :) ^_^

Ads

Related Tutorials/Questions & Answers:

ask user how many numbers to be inputted and determine the sum and highest number using an array in java ask user how many numbers to be inputted and determine the sum and highest number using an array in java

Sum of two numbers using command line arguments in Java Hi, How...? The calculate the sum of two numbers using command line arguments in Java... sum = a+b; Check complete example code at Add Two Numbers in Java. Thanks

Advertisements

determine the top 10 highest and 10 lowest in java hello, I have... java in INDIA, how the programming code in java to rank them. Thank you... that contains the codebooks and namesmembers. I want to make 10 the highest rank anyone

using session variable determine the no of pages viewd by the user using session variable determine the no of pages viewd by the user Hi.../java/jsp/trackuserSession.html Thanks

Sum of a Number using Swing In this section, you will learn how to sum of a number using swing...;); Step: Create a file "Calculate.java" to sum of a number using

. In this section you will learn how to calculate the sum of three numbers by using three... Calculate the Sum of Three Numbers ... how to calculate three integer number . First of all define class name "

A program to find the sum of odd number In this section you will learn how to find the sum of odd number in the series up to the given number in java... number. import java.util.Scanner; public class Sum { public static

read a positive real numbers from highest to lowest write a java program that will read a sequence of 10 positive real nos. entered by the user and will print the same numbers in sorted order from lowest to highest using arrays

How many qusetions can you ask? Hi I was very impressed following my very first question I asked regarding some coding. However I am not sure why any further questions have not yet been answered. Is this because they are more

How to put text file numbers to array and check the position of numbers? I have numbers in text file data.txt 12 9 8 3 1

To find first two maximum numbers in an array,using single loop without sorting array. Java program to find first two maximum numbers in an array,using single loop without sorting array

To find first two maximum numbers in an array,using single loop without sorting array. Java program to find first two maximum numbers in an array,using single loop without sorting array

how to sum(add) two numbers in Java. Check more tutorials at: Java... How to add two numbers in a Java program? In Java you can easily add... numbers in Java it will return you int value as sum of two numbers. In real world

Sum of first n numbers i want a simple java program which will show the sum of first n numbers.... import java.util.*; public class...; } System.out.println("Sum of Numbers from 1 to "+n+" : "+sum

How to using Binary Search Array Java ? Hi, I am beginners in Java Programming Language. I am trying to create small application using Array functions. The problem is that how to use binary search array in Java. Please give

, highest mark, lowest mark, number of students passing, using array. 01 #include<iostream> 02 using namespace std; 03 int main() 04 { 05 int...c++ array find the average mark, highest mark, lowest mark, number of students

, highest mark, lowest mark, number of students passing, using array. 01 #include<iostream> 02 using namespace std; 03 int main() 04 { 05 int...c++ array find the average mark, highest mark, lowest mark, number of students

. The given code accepts the numbers from the user using BufferedReader class. Then using... the sum by the total number of numbers, we have determined the average of numbers...Calculate sum and Average in java How to calculate sum and average

how to authenticate user using TIVOLI api in java? Hi, I want to integrate IBM TIVOLI API to create/authenticate users using java code. Please help....... Thanks in advance

]; } } System.out.println("Sum of positive numbers: "+sum2); System.out.println("Sum of negative numbers: "+sum1...Sum of positive and negative numbers Hi if someone could help

Java number calculation using while loop In this tutorial, you will learn how... and secondNum inclusive. It also find the sum of all the even numbers between...+=num1; } num1++; } System.out.println("Sum Of Even Numbers: "+sum

Number in array How to write a program to check the number that we are entered from keyboard is in the given array

ask a user to enter 5 integer make a program that enter 5 numbers then identify the largest and the smallest number sample program 2 4 3 5 6 the smallest number: 2 the largest number: is 6 66

[ ]={1,2,3,4,5,6,7,8,9,10,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26}; i want to ask user to input one of the above numbers then i want to print the array without the number user input. how will i do tht

java program based on array write a program to create an array of 10 integers in main.accept values from the user in that array .now again ask... count() belonging to a class counter.within count findout how many numbers

how to Insert Array Values Into Separate Rows using java? how to Insert Array Values Into Separate Rows using java? class...) { String array[][]={{"1","Angel","Delhi"},{"2","John","Chennai"},{"3","William

In this section, you will learn how to do one to many mapping using array to retain mapping order in Hibernate

print the sum of even number from 1 to 100 how to print the sum of even number from 1 to 100 using for loops? Thanks

how to convert string to char array in java without using tochararray ...() function. how to convert string to char array in java without using... to char array in java without using tochararray: package my.app; public

one dimensional array using java design and implement a java program that will read a file containing numbers and compute the following statistics: the range(low,high) the average and the median