LLoickinjourney-to-mastery.hashnode.dev·Dec 23, 2024 · 2 min readThe difference between next() and nextLine()nextLine() will store the complete sentence inputted in the String variable whereas next() will only save the first word inputted and the rest will go in an input buffer. If you use a next() then a next(), import java.util.Scanner; public class test1...00
LLoickinjourney-to-mastery.hashnode.dev·Dec 21, 2024 · 1 min readWhen doing a string comparison between the data entered and already set data.Don’t use == as it will not work. import java.util.Scanner; public class Integer{ public static void main(String a[]){ Scanner scanner = new Scanner(System.in); System.out.print("Username: "); String name = scanner.nextLine(); if(n...00
LLoickinjourney-to-mastery.hashnode.dev·Dec 18, 2024 · 1 min readYou could either use an else or put a return outside the if statementpublic int division(int n1, int n2){ if (n2 == 0 || n1 == 0){ return 0; } else{ return n1 / n2; } } or you could use that, since if the condition are met, it will not go through the second ...00
LLoickinjourney-to-mastery.hashnode.dev·Dec 18, 2024 · 1 min readWhen using a return and an if statement, make sure that there is an "else" for unknown outcome for the function to workThat explain why my code was not working00
LLoickinjourney-to-mastery.hashnode.dev·Dec 14, 2024 · 1 min readTry adding the calculation/action in the return of the function.You will be able to reduce the number of lines used00