Java Program : Find Largest Number out of 3 Numbers | Java programming tutorial for Beginners

preview_player
Показать описание
Support Simple Snippets by Donations -
--------------------------------------------------------------------------------------------- In this Java programming video tutorial, we will see a program to find largest out of 3 integer variables in Java.
We will use the If-Else conditional statements to determine the largest out of the 3 int variables and we will see the 2 different ways to achieve this task.

Simple Snippets Official Website -
Simple Snippets on Facebook-
Simple Snippets on Instagram-
Simple Snippets Google Plus Page-
Simple Snippets email ID-
Рекомендации по теме
Комментарии
Автор

Hey Guys, if you want more such tech educational videos on this channel then please support me by subscribing to this channel & also share it with your friends as it helps me create more content just for you ✌

SimpleSnippets
Автор

heres a pseudocode that i've come up with


a, b, c = 1, 3, 2


max = a
if b > max then max = b
if c > max then max = c


return max

atraps
Автор

Instead of writing these many line of code using if else we can use ternary operator and make it more readable and less number of lines as below

package com.crash.company;

import java.util.Scanner;

public class LargeNumber {

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("Enter first number:");
int a = sc.nextInt();
System.out.println("Enter Second number:");
int b = sc.nextInt();
System.out.println("Enter third number:");
int c = sc.nextInt();
int d = (a>b&&a>c)?a:(b>a&&b>c)?b:c;
System.out.println("Largest number is: " + d);
}

}

Ajay-mwtv
Автор

I prefer the last solution thank you, you really helping me. I finally have an Idea to finish my homeworks 😊😊

aubreyjaneomongos
Автор

@9:01, why do you still need y>x in the "else if"?
I mean, we already know that y or z are greater than x (if we are not in the first "if"), so shouldn't we just check to see which is bigger, y or z? why check again if y>x?

like that: (python)
if num1 > num2 and num1 > num3:
largest = num1
elif num2 > num3: #only 1 test here
largest = num2
else:
largest = num3
return largest

matanelp
Автор

THANK YOU BRO YOU HELP ME WITH MY ASSIGNMENTS

keiferramos
Автор

Two no are same and three no are same to kya kare

monsterstatus
Автор

THANK YOU BRO YOU HELP ME WITH MY ASSIGNMENTS

keiferramos