---
title: "How do you write a function that outputs?"  
description: "How do you write a function that outputs?"  
author: "Mukul Goenka"  
published: 2021-11-16  
updated: 2021-11-16  
canonical: https://www.mindstick.com/forum/156841/how-do-you-write-a-function-that-outputs  
category: "c#"  
tags: ["c#", "java", "programming language"]  
reading_time: 2 minutes  

---

# How do you write a function that outputs?

How do you write a [function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) that outputs the largest and the [smallest](https://yourviews.mindstick.com/view/81880/royal-families-of-world-s-smallest-islands-do-fishing) number amongst three [integer](https://answers.mindstick.com/qa/113667/write-code-for-roman-to-integer) inputs? Also, let the user [choose](https://www.mindstick.com/articles/13030/how-to-choose-the-best-online-bitcoin-casino) whether to [end](https://yourviews.mindstick.com/view/88503/us-iran-war-live-updates-trump-says-us-in-no-rush-to-end-iran-war) the [program](https://www.mindstick.com/blog/12337/scaling-up-your-mentorship-program) or not (do while)?

## Replies

### Reply by Mukul Goenka

## Program

```
import java.util.Scanner;public class Main{ public static void main(String[] args) {  findLargestAndSmallest(); }	 public static void findLargestAndSmallest(){     int num=0, max=0, min=0, i=1;        char choose='n';    Scanner sc = new Scanner(System.in);    do{        System.out.printf('Enter %d number : ',i++);        num = sc.nextInt();        if((i-1) == 1){            max = min = num;            continue;        }        if(num>max)        {             max = num;        }else if(num<max && num<min)            min = num;        if(i>3){            System.out.printf('\nYou want to close the program,\nIf Yes then press : Y\nIf No then press : N\n');            choose = sc.next().charAt(0);        }        if(choose == 'Y' || choose =='y'){            System.out.printf('Max value is :%d and Min value is : %d',max,min);            break;        }else{            continue;        }    }while(true); }}
```

Output.

```
Enter 1 number : 34
Enter 2 number : 23
Enter 3 number : 12
You want to close the program,
If Yes then press : Y
If No then press : N
n
Enter 4 number : 0
You want to close the program,
If Yes then press : Y
If No then press : N
y
Max value is :34 and Min value is : 0
```


---

Original Source: https://www.mindstick.com/forum/156841/how-do-you-write-a-function-that-outputs

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
