I continuously watching your videos from the year 2017... It's too great... I learned a lot from your videos.. I have a question to ask you... Till now you uploaded only for C Programming concepts When will you upload data structures concepts? Plz reply me if you see this Thank you neso academy
import java.util.Scanner; class Check { public static void main(String[] args) { System.out.print("Enter an integer: "); Scanner sc = new Scanner(System.in); int n = sc.nextInt(); switch (n % 2) { case 0 : System.out.println(n + " is an even number."); break; default : System.out.println(n + " is an odd number."); break; } } }
import java.util.Scanner; public class Switchassignment { public static void main(String[] args){ Scanner input = new Scanner(System.in); System.out.print("Enter your digit: "); int i1= input.nextInt(); int i2 = i1%2; switch(i2) { case (1): System.out.println("Your digit is Odd = " + i1); break; case (0): System.out.println("your digit is evem = " + i1); break; default: System.out.println("you type wrong digit"); } } } I don't have any idea about coding but because of NESO ACADEMY i fell in love with coding thank you sir💖
Very good explanation but as per I know switch case bit faster and directly it will jump to the case it will not execute every case as you said even if you not put break statement until and unless case satisfies every line verifies in if else
I use the condition (ternary) operator because switch cant test values on every case. Adding a switch for every value to test floods the code. Use this instead: value1 value2 ? ( ifTrue ) : ( ifFalse ) ; It seems faster than if-else. Of course for options and lists and stuff i still use switch. But the video is useful too! I do recommend to use if-else for calling "break;" in "for" and "while" loops.