Did I miss something? What to do if the inputs have the same value? In this code the method returns the first input because of >= but that is not strictly correct in the context of the exercise? Love the tutorials by the way!
This was mine, would this also be acceptable? Thank you. *public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println("Enter number between 1 and 100: "); int input1 = scan.nextInt(); System.out.println("Enter another number between 1 and 100: "); int input2 = scan.nextInt(); System.out.println("You entered the number " + input1 + " and " + input2 + ". The larger number is: " + largerNumber(input1, input2)); } public static int largerNumber(int a, int b){ int answer = Math.max(a, b); return answer; }*
My method is written little bit differently, but works the same way, logic. public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Enter a number between 1 and 100 : " ); int number1 = input.nextInt(); System.out.println("Enter a number between 1 and 100: " ); int number 2 = input.nextInt(); int answer = compareTwoNumbers(number1, number2); System.out.println("You entered the numbers " + number1 + " and " + number2 + " The larger number is: " + answer); } public static int compareTwoNumbers ( int a , int b){ if ( a > b) return a ; else return b; }
This channel is severely underrated. This man is doing God's work
no cap, he deserves more recognition
I agree this channel is so underrated!! Methods literally have brought me to tears and 1 video with this guy and it all makes sense. God bless you!!!
i hope you answer just started learning java and i wanna know why you put the value "1" on your 3 variables?
Did I miss something? What to do if the inputs have the same value? In this code the method returns the first input because of >= but that is not strictly correct in the context of the exercise? Love the tutorials by the way!
This was mine, would this also be acceptable? Thank you.
*public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter number between 1 and 100: ");
int input1 = scan.nextInt();
System.out.println("Enter another number between 1 and 100: ");
int input2 = scan.nextInt();
System.out.println("You entered the number " + input1 + " and " + input2 +
".
The larger number is: " + largerNumber(input1, input2));
}
public static int largerNumber(int a, int b){
int answer = Math.max(a, b);
return answer;
}*
My method is written little bit differently, but works the same way, logic.
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter a number between 1 and 100 : " );
int number1 = input.nextInt();
System.out.println("Enter a number between 1 and 100: " );
int number 2 = input.nextInt();
int answer = compareTwoNumbers(number1, number2);
System.out.println("You entered the numbers " + number1 + " and " + number2 + "
The larger number is: " + answer);
}
public static int compareTwoNumbers ( int a , int b){
if ( a > b) return a ;
else return b;
}
Cristal clear!!!
Why we have assigned 1 to number1,number2 and largerNum?
its not neccsary he does it so that if someone puts a invalid number like a double the program ends instead of error
Mahmoud ali bro I think he forgot something he should have wrote if number >0 &&
Number 1 instructor
watching this in 2022! great explanation
same, i can't believe this course is free