java program based on array

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 the use another nomber and pass the array and the no. entered to function called count() belonging to a class counter.within count findout how many numbers are equal to the no. passed how many are greater and how many are less than the no. passed .finally return the result block to main and print it there.

View Answers

March 14, 2011 at 11:15 AM

import java.util.*;
class ArrayExample8
{
    public static void main(String[] args) 
    {
        int less=0,more=0;
        Scanner input=new Scanner(System.in);
        System.out.println("Enter array elements: ");
        int array[]=new int[10];
        for(int i=0;i<array.length;i++){
            array[i]=input.nextInt();
        }
        System.out.print("Enter number: ");
        int num=input.nextInt();
        for(int i=0;i<array.length;i++){
            if(array[i]<num){
                less++;
            }
            else if(array[i]>num){
                more++;
            }           
        }
        System.out.println("Number of array elements less than "+num+": "+less);
        System.out.println("Number of array elements more than "+num+": "+more);
    }
}









Related Tutorials/Questions & Answers:
java program based on array
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 the use another nomber and pass the array and the no. entered to function called
java program based on array
java program based on array  Create Student class with attributes... StudentDemo which will have main method. Declare array of Student object with size 10. Initialize all 10 elements of this array with new objects. Write logic which
Advertisements
array variable in a java program
array variable in a java program  How do i write a program that will prompt the user for a list of 5 prices, that cosist of the sum of all the prices, the average of the prices, and all prices that are higher than the calculated
array program
array program  write a java program which will take 10 elements as command line arguments and count how many times 3 occurs in array
java 2 d array program
java 2 d array program  write a program 2-d matrix addition through user's input?  Hi Friend, Try the following code: import java.util.*; class MatrixAddition{ public static void main(String[] args
program of array
program of array  write a program that initializes an array with ten random integers and then prints four lines of output,containing:every element at an even index,every even element,all elements in reverse order,and only
program in array
program in array  print("code sample");write a program that initializes an array with ten random integers and then prints four lines of output...(); int arr[]=new int[10]; System.out.println("Array of Random
create and use an array variable in a java program
create and use an array variable in a java program  how do i write a program that will prompt the user for a list of 5 prices, once the user has entered all values , your program should compute and display the following: The sum
Array list java program - Java Interview Questions
Array list java program  Create an employee class with an employee... an employee id is given, display his name & address? Please provide the DETAIL java... we can display his name and address when an employee id is given? i need java
Program to implement array of Objects.
Program to implement array of Objects.  Create a class it has.... Initialize an array of objects. Pass a name from the command line & search for the name in the array of objects , if it is existing print the information
how to make a program on array
how to make a program on array  When you make a program on array that the element will move downward and upward and when you input twice 0 then thats the time that it will not move. pls. give me a formula...tnx
one dimensional array program
one dimensional array program  Design and implement a java program that will read a file containing numbers and compute the following statistics: the rannge( low, high), the average and the median(middle number). Notes
Two Dimensional array program
to elements of the array such that the last element become the first one and the first become the last.let the program output elements of the first array...Two Dimensional array program  consider a two dimensional array
Three Dimensional Array program
Three Dimensional Array program       This is a very simple Java program. In this program we... the multidimensional array we are going to make a matrix. Now in this program use
Reverse integer array program
Reverse integer array program  Been tasked with the following question: Write a method that accepts an integer array and returns a new array with all the elements in reverse order. For example, if the input array is [2, 4, 6, 8
Two Dimensional Array Program
;    This is very simple program of Java. In this lesson we will learn how to display arrange form of two dimensional array program... a integer for array declaration Two dimensional array program. We are going
program to implement array of objects
program to implement array of objects  import java.io.*; import java.util.*; public class dataa { DataInputStream in=new DataInputStream(System.in); int i; int a[i]=int acid[5]; String name1[i]=new String[5
Two Dimensional Array Program
Two Dimensional Array Program Using Nested for loop       This is a simple Java array  program . In this session we will teach how to use of a two dimensional array
Java array
Java array  Java program to find first two maximum numbers in an array,using single loop without sorting array
Two Dimensional Array Program Using Nested For Loop
Two Dimensional Array Program Using Nested For Loop        This is very simple program... dimensional array program. Firstly, we have to define class "TwoDimensional "
Changing the value of Array in Java
array program is provided Java application program about the explanation... Changing the Value of Array in Java       This is very simple of one dimensional array program
Java Array
Java Array   a) Write an array program that perform the following: i) Declares a String array initialized with the following strings: ΓΆβ?¬Ε...?¬Β?. ii) Write a loop that displays the contents of each element in the array
Java array
Java array   How can one prove that the array is not null but empty
java array
java array  q4.array Write a program that accepts two arrays, an array of fruit names and an array of price of fruits, and a fruit name and returns the price of the fruit. (Assume that a price in the second array corresponds
java program
java program  write a java program to display array list and calculate the average of given array
java program
java program  write a java program to display array list and calculate the average of given array
java array
java array  write a java method that takes an array of float values...)){ System.out.println("There are duplicate elements."); Float array...++){ array[i]=new Float(arr[i]); } Set<Float>
java program
java program  write a java program to create an array of size 10 by taking input from bufferreader and find out the average of array elements from that array
java program
java program  write a java program to create an array of size 10 by taking input from bufferreader and find out the average of array elements from that array
java program
java program  write a java program to create an array of size 10 by taking input from bufferreader and find out the average of array elements from that array
java program
java program  write a program to read 10 numbers from user and store it in a array. display the maximum n minimum number in the array
What is Array in Java?
What is Array in Java?  Hi, What is Array in Java? How to create an array in Java and use it? Thanks   Hi, Array is very important in Java as it is used heavily in programming. Array is Java is a container object
The Array Palindrome Number in Java
The Array Palindrome Number in Java       This is a Java simple palindrome number program... program. The array palindrome number arrange the array number. This session
Use of Array in Java
Use of Array in Java      ... that you can write a program on array by yourself. An array works a container... to define array is just same as we have defined an array in the program below. 
JAva program
JAva program  Write a JAva program that takes various string from command line and display them in sorted order.   Java display strings...); System.out.println("Enter 5 strings: "); String array[]=new String[5
java array
java array Two cells is a matrix will be called connected if they are adjacent...], a[3,2], a[3,3] } elements with weight 6 Problem: Implement Java code which takes 2 dimensional integer array as input and prints out heaviest island
jagged array in java
jagged array in java   jagged array in java with example
Java Program
Java Program  I want to Write a program in JAVA to display to create a class called MATRIX using a two-dimensional array of integers. Perform the addition and subtraction of two matrices. Help me
array and string based problem
array and string based problem  this program is accepting only..._srt(int array[],int n){ for (int j = 0; j < n; j++){ int i = j-1; int k = array[j]; while ((i>= 0) && (array[i] > k)){ array[i
array and string based problem
array and string based problem  this program is accepting only..._srt(int array[],int n){ for (int j = 0; j < n; j++){ int i = j-1; int k = array[j]; while ((i>= 0) && (array[i] > k)){ array[i
array and string based problem
array and string based problem  this program is accepting only..._srt(int array[],int n){ for (int j = 0; j < n; j++){ int i = j-1; int k = array[j]; while ((i>= 0) && (array[i] > k)){ array[i
Array in Java
Array in Java  public class tn { public class State{ String s_name; int p1; int p2; } public void f(){ State[] s = new State[10]; int [] i = new int[10]; i[0] = 1
PHP Array
PHP Array In this page we will learn about PHP Array. We will also understand how to use PHP Array in your PHP program. The PHP Array is very useful in developing PHP based applications. PHP Arrays are ordered map which is used
Java Array
In this section, you will learn about array in Java
Array in Java
_TO_REPLACE_1 Different types of array used in Java are One-dimensional, Two...}{80,90,100,110}; 3 steps are followed while using an array in a program... of an Array Arrays in Java for different data types can be declared as follows
java program
java program  my array size is 10, then how can i identify class A object from array. Q) how jvm know a particular object is serialize
Java program
Java program  Write a java program which reads in a file, whose name... for all persons in an array of objects using Tokenizer class to separate data... the persons who has the smallest and largest weights. ΓΆβ?¬ΒΆ To sort the array
char array java
char array java  char array programmes in java All capital letters should be replaced with the next letter
Java Program
Java Program  Helle can anyone provide me one example... and class instantiation. Write a method that processes a file based on given... that manipulates the data in an array
sorting array in java
sorting array in java  How to sort array in Java or JavaScript?   JavaScript Sorting array tutorial   Java Sort array of strings...[] args) { String array[]=new String[5]; Scanner input = new Scanner

Ads