Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 26-11-2009
Member
 
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.
Reply With Quote
  #2  
Old 26-11-2009
Member
 
Join Date: Oct 2005
Posts: 2,389
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");
      }
    }
  }
}
Reply With Quote
  #3  
Old 26-11-2009
Member
 
Join Date: May 2008
Posts: 2,383
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;
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
  #4  
Old 26-11-2009
Member
 
Join Date: Feb 2008
Posts: 1,848
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];
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


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


All times are GMT +5.5. The time now is 07:36 AM.