Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Java static method

Problem Statement : To find the largest among three using a Static method.

Algorithm
  • Start
  • Create a class Lar
  • Define static method find(int a,int b,int c)
  • find(8,15,10)
  • find(75,20,89)

Function static void find(int a,int b,int c)

  • Start
  • int big
  • if(a>b) go to 4 else to 7
  • if(a>c) go to 5 else to 6
  • big=a go to step 10
  • big=c go to step 10
  • if(b>c) go to 8 else to 9
  • big=b go to step 10
  • big=c
  • print big
  • Stop
Program
import java.io.*;
class Largest
{
	public static int FindLargest(int a,int b,int c)
	{
		int larg;
		if(a>b)
			if(a>c)
				larg=a;
			else
				larg=c;
		else
			if(b>c)
				larg=b;
			else
				larg=c;	
	 	return larg;
	 }   
}

public class MyLagest {
	public static void main(String[] args) {
		int a,b,c,largest;
		DataInputStream in=new DataInputStream(System.in);
		try
		{
			System.out.println("Enter three numbers : ");
			a=Integer.parseInt(in.readLine());
			b=Integer.parseInt(in.readLine());
			c=Integer.parseInt(in.readLine());
			largest=Largest.FindLargest(a,b,c);
			System.out.println("Largest : " + largest);
		}
		catch(Exception e)
		{		
			System.out.println("Error : "+ e);
		}
	}
}


Output

Enter three numbers :

25

636

33

Largest : 636

Java static method is a post from ShoutToWorld - Let's Learn Let's Shout - Helping bloggers and developers.



This post first appeared on ShoutToWorld, please read the originial post: here

Share the post

Java static method

×

Subscribe to Shouttoworld

Get updates delivered right to your inbox!

Thank you for your subscription

×