Results 1 to 4 of 4

Thread: program to find the largest value in java.

  1. #1
    Join Date
    Nov 2009
    Posts
    50

    program to find the largest value in java.

    Hello,
    I am new to java programming language.I just started learning Java language.Yesterday our sir has given one program to find largest number.I used various method but I unable to write that program .So I asked this question on this forum.Please help me.

  2. #2
    Join Date
    Oct 2005
    Posts
    2,393

    Re: program to find the largest value in java.

    This is simple program where you have to compare one value with another.



    Code:
    class largestnum
       {
        public static void main(String[] args) 
        {
        int p=500, q=70, r=3000;
        if (p>y)
     {
          if (p>z){
            System.out.println("p is greatest number");
          }
          else
           {
            if(z>q)
            {
              System.out.println("r is greatest number"); 
            }
            else{
              System.out.println("q is greatest number");
            }
          }
        }
        else{
          if (q>r)
           {
            System.out.println("q is greatest number");
          }
        }
      }
    }

  3. #3
    Join Date
    May 2008
    Posts
    2,389

    Re: program to find the largest value in java.

    This is a simplest code to find largest value.




    Code:
       
          int p;
     
          int i = 0;
      
          int largestnum;
    
          largestnum = num[0];
    
          for(p =0; p < num.lenght(); p++)
     
          if(largestnum < num[p])
      
          {
       
          largestnum = num[p];
      
          i = p;
      
          }
     
          return i;

  4. #4
    Join Date
    Feb 2008
    Posts
    1,852

    Re: program to find the largest value in java.

    I suggest you to first sort your number using array then you can find largest value as last element.In java there is one function called Arrays.sort that can be used to sort number.

    use following approach:

    java.util.Arrays.sort(numbers);
    largestNumber= numbers[lalues.length-1];

Similar Threads

  1. Dr. Java program
    By bamggut29 in forum Software Development
    Replies: 2
    Last Post: 26-11-2011, 04:24 AM
  2. How to write java program to find factorial of number?
    By Balamohan in forum Software Development
    Replies: 5
    Last Post: 28-11-2009, 10:14 PM
  3. How to find second largest value from array
    By Jaheel in forum Software Development
    Replies: 3
    Last Post: 18-11-2009, 11:42 AM
  4. Link List Example in Java Sample program in Java
    By trickson in forum Software Development
    Replies: 2
    Last Post: 04-08-2009, 08:23 PM
  5. Find Largest No
    By kelfro in forum Software Development
    Replies: 1
    Last Post: 10-01-2009, 07:44 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,121,314.69140 seconds with 16 queries