Java Programming Tutorial – 10 – If Statement

Home/Programming Video Tutorials/Java Video Tutorials/Java Programming Tutorial – 10 – If Statement

Java Programming Tutorial – 10 – If Statement

FavoriteLoadingAdd to favorites

Facebook – https://www.facebook.com/TheNewBoston-464114846956315/
GitHub – https://github.com/buckyroberts
Google+ – https://plus.google.com/+BuckyRoberts
LinkedIn – https://www.linkedin.com/in/buckyroberts
reddit – https://www.reddit.com/r/thenewboston/
Support – https://www.patreon.com/thenewboston
thenewboston – https://thenewboston.com/
Twitter – https://twitter.com/bucky_roberts

Java468x60
By | 2017-06-02T00:23:21+00:00 June 2nd, 2017|Java Video Tutorials|49 Comments

49 Comments

  1. Drunk Dog June 2, 2017 at 12:24 am - Reply

    Made a code that tell you if the variable you defined is even or odd

    import java.util.Scanner;
    class IFstat {
    public static void main(String args[]){
    Scanner crappy = new Scanner(System.in);
    int test;
    System.out.println("Enter a number: ");
    test = crappy.nextInt();
    if (test%2 == 0){ //testing if User defined variable is even or odd. ‘!=’ is not equal to sign
    System.out.println("The number is even");
    }
    else {
    System.out.println("The number is odd");
    }
    }
    }

  2. maher elsayed June 2, 2017 at 12:24 am - Reply

    try this
    import java.util.Scanner;

    public class tutorisl10 {

    public static void main (String args[]){

    Scanner kety = new Scanner(System.in);
    double fnum, snum, answer;
    int x;
    System.out.print("enter the first number: ");
    fnum=kety.nextDouble();
    System.out.print("pls. enter the second number: ");
    snum = kety.nextDouble();
    System.out.println("choose the operation:");
    System.out.println("1>sum…..2>subtract…..3>multiply…..4>division");
    System.out.print("ur choice: ");
    x=kety.nextInt();
    if(x==1){
    answer = fnum + snum;
    System.out.print("your answer= ");
    System.out.print(answer);
    }else if(x==2){
    answer = fnum – snum;
    System.out.print("your answer= ");
    System.out.print(answer);
    }else if(x==3){
    answer = fnum * snum;
    System.out.print("your answer= ");
    System.out.print(answer);
    }else if(x==4){
    answer = fnum / snum;
    System.out.print("your answer= ");
    System.out.print(answer);
    }else System.out.print("invalid choice");
    }
    }

  3. GobblowGalaxyGamer June 2, 2017 at 12:26 am - Reply

    @5:32 sounds like he jizzed his pants.

  4. Mayank Patel June 2, 2017 at 12:28 am - Reply

    Hello Sir, could you please let know how to put restrain to int age( <=0) should be error. I tried to do it from your tutorial, however I am not getting the result. – Yours Sincerely.

    Hello Sir, I tried again my problem after seeing from your tutorial; I got the result. Thank you for your tutorial.

    Also, could you let me know how can we write a command to put restriction to int !=double. I wrote this in a if statement, but it did not work. If an user enters double value instead of int, it should not get crash, or could you please let me know in which this command may be; I will learn it from it.
    – Yours Sincerely.

  5. Xelenium June 2, 2017 at 12:29 am - Reply

    How can I convert a Scanner into a String? So I can for example compare the user input with text?

  6. C Pavon June 2, 2017 at 12:30 am - Reply

    *FEMINISM TRIGGERED*

  7. leadsled2020 June 2, 2017 at 12:34 am - Reply

    So I decided to take this one step further and try to create a functioning simple calculator, but it will not give me any output. Anybody have any ideas?

    import java.util.Scanner;
    class calculator {
    public static void main(String args[]){
    Scanner chris = new Scanner(System.in);
    double fnum, snum, answer;
    String operator;
    System.out.println("Enter First Number: ");
    fnum = chris.nextDouble();
    System.out.println("Enter + – * or /: ");
    operator= chris.next();
    System.out.println("Enter Second Number: ");
    snum = chris.nextDouble();

    if(operator =="+"){
    answer = fnum + snum;
    System.out.println("The answer is: ");
    System.out.println(answer);
    }
    if(operator =="-"){
    answer = fnum – snum;
    System.out.println("The answer is: ");
    System.out.println(answer);
    }
    if(operator == "*"){
    answer = fnum * snum;
    System.out.println("The answer is: ");
    System.out.println(answer);
    }
    if(operator == "/"){
    answer = fnum / snum;
    System.out.println("The answer is: ");
    System.out.println(answer);
    }

    }
    }

  8. Junbo Chen June 2, 2017 at 12:36 am - Reply

    Thanks this is useful

  9. max klotsman June 2, 2017 at 12:36 am - Reply

    I love you
    seriously you made my life a thousand times easier. thank you bucky.

  10. GabeHero June 2, 2017 at 12:37 am - Reply

    it says that the "else" is a syntax error, why?

  11. Marko Francuski June 2, 2017 at 12:37 am - Reply

    Hello there is there like any elif in java, like in python? or i have to do if (condition1), then else and in else block another if statement ?

  12. Darren Maguire June 2, 2017 at 12:39 am - Reply

    You do some great tutorials, does anyone know of any other useful tutorials online? Maybe some that incorporate some challenges as well. Cheers.

  13. Rahul Berry June 2, 2017 at 12:39 am - Reply

    this is awesome

  14. Cem Alp June 2, 2017 at 12:42 am - Reply

    I made this one;

    import java.util.Scanner;
    public class varg {

    public static void main(String[] args) {
    **** Scanner enter = new Scanner(System.in);
    int age;
    System.out.println("Enter your age: ");
    age = enter.nextInt();
    if (age >= 18){
    System.out.println("You can enter");
    } else{
    System.out.println("Too young");
    }

    }

    }
    and it says "enter" never closed in ***line. so what am i missing here ?

  15. ranimations June 2, 2017 at 12:42 am - Reply

    Finally dude finally you are awesome

  16. Retarded Producer June 2, 2017 at 12:43 am - Reply

    TRIGGERED. THERE ARE 300000000000000000000000000000000000000000 GENDERS U SEXIST SICK HUMAN BEING.

  17. HH AA June 2, 2017 at 12:43 am - Reply

    triggered

  18. zarmina ehsan June 2, 2017 at 12:43 am - Reply

    can anyone explain me what is the difference between publlic class and class? ( I am asking this because I couldn’t make a calculator with public class.)

  19. Slowest Sundew7 June 2, 2017 at 12:44 am - Reply

    This is one of my favorite parts, because if statements are used so MUCH and are so cool to play around with it.

  20. lisa tran June 2, 2017 at 12:46 am - Reply

    thank you so much for ur videos, its very clear and easy to learn. I am in my first java class and was very confused . i appreciate your help .

  21. 김혜린 June 2, 2017 at 12:46 am - Reply

    sometimes i see if statements without the curly braces [in my ap comp class the tests are written w/o them], is this considered bad syntax or would that still run? is it just a matter of organisation?

  22. Dimitar Penev June 2, 2017 at 12:46 am - Reply

    Hey thank you so much for making these, they were incredibly helpful.

  23. HUMZA shahzad June 2, 2017 at 12:49 am - Reply

    Can anyone tell me why this doesnt work? it keeps saying the operator <= is undefined.
    package dicks;

    import javax.swing.JOptionPane;
    import java.util.Scanner;

    public class dicknudes {
    public static void main(String[] args) {
    JOptionPane.showInputDialog("How big is your dick?");
    Scanner scanner = new Scanner(System.in);
    if(scanner <= 6) {
    JOptionPane.showMessageDialog(null, "lul u have a small dick niggerfaggot");
    }else {
    JOptionPane.showMessageDialog(null, "stfu bitch we all know you have a tic tac dick put the truth in nigger");
    }
    }
    }

  24. Max van Over June 2, 2017 at 12:56 am - Reply

    For the love of god, learn how to use hot keys.

  25. V. Peters June 2, 2017 at 12:57 am - Reply

    public class course10 {
    public static void main(String args[]){
    int test = 6;

    if (test < 9){
    System.out.println("yes");

    } else {
    System.out.println("this is else");
    }

    }
    }

  26. Suhina Chotoki June 2, 2017 at 12:57 am - Reply

    I swear all your videos are the reasons I’m passing my java classes right now! better than my lecturers! Thank you!

  27. FroglickPlays June 2, 2017 at 12:58 am - Reply

    He said if you were a "boy" or "girl" TRIGGERED!

  28. Jay jh 1993 June 2, 2017 at 12:58 am - Reply

    i like to call curly braces moustaches cuz they look like moustaches

  29. Zhelyazko Georgiev June 2, 2017 at 12:58 am - Reply

    the first time i hear someone explain to me the difference between "=" and "==". ty bro.

  30. Chris June 2, 2017 at 12:59 am - Reply

    That improper convention @ main..(not that it matters)

  31. Kristian011 June 2, 2017 at 1:02 am - Reply

    Amazing! I am curently learning C++ and didn’t want to go into other complicated languages, but i gave it a try and i understanded everything perfectly! I am so excited to continue your tutorials :3

  32. majid ALi June 2, 2017 at 1:02 am - Reply

    Sir please tell me editor name

  33. Jane E June 2, 2017 at 1:03 am - Reply

    how do you set the java program as when you input an integer, it will direct you to an output if it satisfies the if "statement", and another output if it satisfies the "else" statement?

  34. Mohamed Abd El Aal Ibrahim June 2, 2017 at 1:03 am - Reply

    Great one bucky

  35. GifKing June 2, 2017 at 1:03 am - Reply

    Did he just assume my gender?

  36. Alex Paredes June 2, 2017 at 1:06 am - Reply

    how can i use if…else statement if my gross is 0-300 with 10% tax and 300.01-400 with 12% tax plus using method call?

  37. Programming Diaries June 2, 2017 at 1:11 am - Reply

    the best online tutorials thanx

  38. MEEP June 2, 2017 at 1:12 am - Reply

    what if I’m non binary? hahaha

  39. Raamiz Hussain June 2, 2017 at 1:13 am - Reply

    What about the elseif statement? What’s that in java

  40. Elton Saraçi June 2, 2017 at 1:13 am - Reply

    I’ll fucking say "Thank You" in every single video of yours, lol/

  41. Them Plays June 2, 2017 at 1:13 am - Reply

    my first day in learning java and i already can translate my thoughts to a computer THANKSSSS
    import java.util.Scanner;
    public class classes {
    public static void main (String args[])
    {
    System.out.println("WHO ARE YOU");
    System.out.println("male or a boy");
    System.out.println("1 for male and 2 for female");
    Scanner lul=new Scanner(System.in);
    int male,female;
    male=1;
    female=2;
    if (lul.nextInt()==1)
    {
    System.out.println("you are a woman");
    }
    else {
    System.out.println("you are a woman");
    }

    }
    }

  42. DPowered Smith June 2, 2017 at 1:14 am - Reply

    HOW DARE YOU ASSUME MY GENDER!!

  43. Salar Amir June 2, 2017 at 1:14 am - Reply

    for One Piece fans 😀

    public class If_Statement {

    public static void main(String[] args) {
    int Luffy = 100;
    int Pirate = 100;
    int King = Pirate – Luffy;

    if (Luffy == 100) {
    System.out.println("Luffy is the king of the pirates!");
    }else {
    System.out.println("Luffy is not the king of the pirates yet!");
    System.out.println("He Still needs " + King + " power!");

    }

    }

    }

  44. real Coffei June 2, 2017 at 1:15 am - Reply

    ik i may be a little bit late but if i wanted to write an if/else statement to see if they have the same name as me, how would i do that

  45. Dean De Ridder June 2, 2017 at 1:16 am - Reply

    Dude, best: not boring, non annoying voice, tutorial ever! I’m really getting this ! Thanks!

  46. Riddlebounce June 2, 2017 at 1:19 am - Reply

    Drink everytime he says test and try to finish the video lol!

  47. Harshal Patel June 2, 2017 at 1:19 am - Reply

    public class Apples{
    public static void main(String args[]){
    int bucky = 5;

    if (bucky == 5){
    System.out.println("Bucky is the best!");
    }
    else{
    System.out.println("Bucky is still the best!");
    }
    }
    }

  48. Codebox42 June 2, 2017 at 1:21 am - Reply

    Does this work with Netbeans?

  49. Clash with A Square June 2, 2017 at 1:21 am - Reply

    i took a little time and created this it may not be that great but i feel proud of it

    import java.util.Scanner;
    class ashim{
    public static void main(String args[]){
    Scanner text = new Scanner(System.in);
    int answer;
    int a, b, c, d;
    a=1;
    b=2;
    c=3;
    d=4;
    System.out.println("what is your the capital of nepal?");
    System.out.println("1.kathmandu 2. pokhara" );
    System.out.println("3.jhapa 4. birjung");
    answer= text.nextInt();
    if(answer==1){
    System.out.println("you have answered first question now move towards second.");
    System.out.println("who is the football play with most no. of goals?");
    System.out.println("1.messi 2.c.ronaldo points=5");
    System.out.println("3.pele 4.maradona");
    answer= text.nextInt();
    if(answer==3){
    System.out.println("congrats!! you have answered teo questions right…. points=10");
    System.out.println("who created this great programme?");
    System.out.println("1.mark zukeberg 2.bill gates");
    System.out.println("3.pm of clafornia 4.Ashim dahal");
    answer= text.nextInt();
    if(answer==4){
    System.out.println("you scored 20 points and are a person with good iq.. thanks for playing and tell me about the peogramme..");
    }else{
    System.out.println("plz restart the game coz u have given wrong answer");
    }
    }else{
    System.out.println("plz restart the game coz u have given wrong answer");
    }
    }else{
    System.out.println("plz restart the game coz u have given wrong answer");
    }
    }
    }

Leave A Comment

*