@TheTingism but if its greater than or equal to it does matter, because if you had age>=40 first and then age>=60 and u had the age 65 inserted, it would say ur in ur 40s because 40 was first
I just have one giant java project which asks you questions that make no sense, but I try and apply all the new things I learn from these tutorials into it. I would suggest anybody who's having trouble to do the same since it really gets you familiar with the language.
@SathApoc i know this looks really wierd, but i had to make it like that to have enough space. Can someone tell me why this dosnt work? First number worked fine, but after i typed a number, then enter, it just says "Plus or minus?You did something wrong.Second number: ", and if i write a number, i get 0.0. Any help? :)
@jakspyder I am not confused about this logic. I've just mentioned that in that exact tutorial, in that exact example, this thing was made in the way I've described, that's all. It was not a question and misunderstanding, so stop answering me, especially with that dumb stuff like TheSandvichTrials wrote.
I cant figure out what i should write if i want to be able to first type in the age, and then get the answer. Ive imported the scanner, i wrote: Scanner age = new Scanner(System.in); and after that: age.nextLine(); when i write the if statement, using the variable age, it doesn't work? :( What have i donw wrong? help please!
@SPlRO If the if statement is one line, you dont need a curly brace. The same applies to else statements. But, the only exception is in nested if statements. you can have
@SPlRO curly braces are for organizational purposes... Very good to get used to because when you get farther in its hard to keep track of what is inside of what.. As well as nesting statements..
You don't really need (at least not for these simple conditions). But once the conditions become many and comprehensive, it gets much more organized and structured with curly brackets, and I believe in some cases you'll actually get errors without them. not sure tho ;)
Ok all three of you I'm going to clear up the misunderstanding. When you have 1 action inside the if statement, curly braces are NOT necessary. However, when you want multiple actions inside the if statement, you have to use curly braces. If you don't, the program probably will not get an error, but the 2nd, 3rd, 4th, etc. actions will perform even if the if condition is false, because they are not part of the whole if this then do that thing.
when i was taught programming in the beginning , else if statements we strongly discouraged and having only 2 conditions with nested if statements were widely used.. I still use this principle to this day! sometimes when im working on a larger project and feel lazy will i create more than 2 conditions using the else if statements :P oh how programming has evolved!
@ChrisTheBest1992 it is considered good syntax to use else if statements because on a larger scale a program will run more efficiently or quicker if you use if/else rather than seperate if statements.
Awesome tutorial but wouldnt it make more sense if you could enter ur age and after that it told you "youre in your 40s" or whatever? (and i know, there is another tutorial on how to do that stuff)
@soldado1997 Because if you just put a bunch of if's, it'll test each one and if you put one if and all the following ones as else if, once a test comes out positive, it doesn't go on to check the rest of the tests!
public static void main(String[] args){ Scanner ages = new Scanner(System.in); int age = 0; System.out.println("Enter your age here"); age = ages.nextInt(); if (age > 17) System.out.println("You are " + age + "yrs old, access granted!"); else System.out.println("You are to young, you are: " + age);
Ha! I made bmi calc when he teached math and if statements, this should be teached earlier 'cause this is important. Also remember to apply the contents of these tutorials and you'll discover more and most importantly learn.
Aren't "nested if statements" (the previous tutorial) and "else if statements" the same thing? The only difference I can see is that for "else if", you put "if" BESIDE "else" rather than on a new line.
@MisterM2402 the nested if statements will make it print two lines (the initial statement then the nested one) The else if only prints whatever line applys
ok so i was going smoothly through all of his tutorials until his brackets started ending up farther to the right then mine...idk wth has happened but now my code gets all messed up :/ help plz...
@t89pepper What do you mean by his brackets started ending up farther to the right then yours? If you mean that some of his code seems to be more to the right than yours is, that doesn't really matter. What matters is that the syntax is correct. Make sure all of the curly braces are properly opened and closed, and that you have semi-colons where there should be, and it should work fine.
Hey guys answer me please. How do I use "if" statement from user input. For example. System.out.println("Are you a MALE or a FEMALE, type f/m: "); , I want to use an IF statement that is going to react based on what I type to the program (f, or m) Please help thanks
@fearlessftw Make a variable(string or char it doesnt matter) to save the information you are going to scan. after that use of the if statement with the variable you just created... my suggestion use an elseif in case the person make a mistake and type something different from M or F
@JamesCalex true programmer get reviled. And idiots who were just along on the ride to "prove to them selves" that they can learn java quit. caz they can't processes the awsomeness of java :D
@TheWondererMan no no no no this is completly different thing. Switch statement is for exact numbers (if im not frong) and if is more for not so exact numbers. Switch for 1,2,3,4,5,6... and if for numbers between 2 numbers. And that should have made sense..
coming from python we use elif for else if. for java does else if have to be between if and else? or can it be used like python one if and the rest elif?
It's funny how after each video, the number of views decrease...shows how much dedication and determination people have for the language...quitters! =P
There are a ton of these things: If statements, switch statements, nested if statements, else if statements...
I think you can make the same program with any of them, but some are faster. So far I feel nested ifs are a little too confusing for my taste, and switch statements seem to work perfectly fine for most things.
Does anyone know how to use a string imported from the scanner in a switch/if/else if statement. I really need to be able to do that for a program im working on.
@NEDinACTION import the scanner (import java.util.Scanner;) create the class System.out.println("Enter your string"); Scanner yourScanString = new Scanner (System.in); String yourTestString = scan.nextLine(); if (yourTestString == whatever){ enter code if result is true. else{ enter code if result is false } } If you want if else, switch, case etc. It is EXACTLY as he has shown in videos, just save the input to a string, and use the string as the test variable.
Guys, just so you know what you learned today here's a quick sumaray. Else if statements are convieneint because it saves you the trouble of making multiple if statements which reuire a new set of braces each time you type them. Else if statements are more like switch statements-easy to type, simple, and neat-, but they are not nearly as specific as switch statements because you can choose from a wide range of numbers. Switch statements can only select one number at a time.
@TheGreekSkater The else if-statement is like the else-statement but with a condition. So if the if-statement before an else if-statement is false but else if is true the code in else if will be executed. If they're both true only the if-statement will be executed.
If you use two if-statements instead both will be executed if they're both true.
Isn't this just an easier, tidier way to do the Nested If's? As I wrote up something from ages <=5 to over 120. With different replies, using the nested ifs like If THIS! do that }else{ If THIS! do that }ELSE{ then i had lots of }}}}}}} at the end of the script. Then I've just shortened that script I wrote by using:- If THIS do that ELSE IF THIS do that ELSE IF THIS do that ELSE do this. Or is there another use for Nested If's? did i miss something? :S pls help someone, Tnx!
the braces can be omitted if no multiple actions will be executed if you will only print a string, you may not include a brace as long it is included in the if or else statement :)
@AliahBishr if You dont put brackets You can only add one next line, if you put two or more it will prompt an error, so it safer and cleaner to put those bracketes every time imo, e.g. when you want to put another line of code later on
@AliahBishr the only two solution i came up with is that braces consume time when computer is reading them so first programmers decided to gain some time and exclude braces from one line statements when it was possible, but thats pretty stupid imho... OR, they have small terminals that displayed only like 24 lines of code which is more possible i think. "(...)By bracing every if, else, while, etc.—even single-line conditionals— insertion of a new line of code anywhere is always "safe"."
Bucky, you rock! Just one comment, your previous 'IF' tut used curly braces around the 'IF' and corresponding 'ELSE' statements, in this tutorial you omit them; is it better to do it with or without curly braces?
@vinchisel If you need more than 1 line of code in your if/else/else if statements, use curly braces. If you only need 1 line, it doesn't really matter.
Eclipse is telling me "Syntax error on token "else" delete this token."
I'm confused. :/
class cake { public static void main(String[] args) { int age = 55; if(age > 60); System.out.println("You're a senior citizen."); else System.out.println("You're a young buck."); }
Is it true that the ELSE IFs order matters????? The program would return the printout for the first TRUE condition???
TheTingism 1 day ago in playlist Java (Beginner) Programming Tutorials
@TheTingism but if its greater than or equal to it does matter, because if you had age>=40 first and then age>=60 and u had the age 65 inserted, it would say ur in ur 40s because 40 was first
AwesomeVideos300 1 day ago in playlist Java (Beginner) Programming Tutorials
lol so they get russian on a makeshift security guard lol
dragonthewatcher 1 week ago
@dragonthewatcher so again thank you and ill see you next door (as he winks)
dragonthewatcher 1 week ago
these are so helpful, thanks man, keep up the hard work
vasti009 1 week ago
what now you do not need to have {}
gustavboll1 2 weeks ago
@gustavboll1 because because it is a single line of code
Metgeoz 2 weeks ago
@Metgeoz ok...
gustavboll1 2 weeks ago
you really right-clicked and copy? You're a programmer dude!!
You spelled Ctrl + C and Ctrl + V wrong
vostidi 2 weeks ago
constructors were kinda more fun than if else statements
slim2kev 1 month ago in playlist java program
@slim2kev Yes, so as to me. :)
MyJavaRoadMap 4 weeks ago in playlist Java (Beginner) Programming Tutorials
@slim2kev Nah, I think if else statements are more fun.
GeorgeUnitt 3 weeks ago in playlist Java (Beginner) Programming Tutorials
Why not use a Switch statement?
6dark6alex6 1 month ago in playlist TheNewBoston Java Playlist 2
@6dark6alex6 In switch statement, you can only test the value of one variable, while there you can do else if (1 > 0), things like this.
PythonicRobot 1 month ago
@6dark6alex6 Switch can only be used with specific values like 1-100 and so on or A-Z/a-z
MyJavaRoadMap 4 weeks ago in playlist Java (Beginner) Programming Tutorials
lol bucky knows almost every programming language you can imagine but he doesn´t know how to use Ctrl+C and Ctrl+V
JakobRobert00 1 month ago 28
@JakobRobert00 he knows c+... i know +C ^^
dragonthewatcher 1 week ago
Comment removed
gijshermans 1 week ago
@JakobRobert00 Well, maybe does his keyboard not contain a ctrl key.
gijshermans 1 week ago
@JakobRobert00 I don't think he cares to even use it. He's just trying to show the basics from the basic forms without using those shortcuts.
carshowkings408 1 week ago
its fun to watch how the view counter falls when we get more into the series xD
asgerkill 1 month ago in playlist Java Programming Tutorials
when do you learn how to make a game?
MrSilentknight12 1 month ago
@MrSilentknight12
depends on your work, mby less than half year
devilazpl 1 month ago in playlist Java Programming Tutorials
How The F Dislikes This????!!!!???
persiaTUT 1 month ago
THIS IS NOT OUTPUTTING ANYTHING!
thejord1000 2 months ago in playlist Java Programming Tutorials
"so they get a russian on makeshift security men share of"
Nice one google...
TheFinTV 2 months ago
I just have one giant java project which asks you questions that make no sense, but I try and apply all the new things I learn from these tutorials into it. I would suggest anybody who's having trouble to do the same since it really gets you familiar with the language.
TheDudeThatPwns 2 months ago
"In the middle of the if and else, you put something called an 'else if'" Very creative name.
LordShlump 2 months ago in playlist Java Programming Tutorials
SathApoc 2 months ago in playlist Java Programming Tutorials
@SathApoc i know this looks really wierd, but i had to make it like that to have enough space. Can someone tell me why this dosnt work? First number worked fine, but after i typed a number, then enter, it just says "Plus or minus?You did something wrong.Second number: ", and if i write a number, i get 0.0. Any help? :)
SathApoc 2 months ago in playlist Java Programming Tutorials
@SathApoc Try using two different Scanners for double and string type
adnamohd 2 months ago in playlist Java Programming Tutorials
These are great man. Thanks!
Tyfreaky1 2 months ago
Java is complicated, and you make it simple. Only 68 more to go. Thank you!
SurvivaloftheMiner 2 months ago
here if you put "if age >=40" higher than "if age >=50", then you are going to be in your 40s even if you are in your 80s ...=\
Everlovingful 3 months ago
@Everlovingful thats what tutorial 11 goes over you can use for example "If age >=40 && age <=49" Pay attention! :P Good luck!
jakspyder 2 months ago
Comment removed
Everlovingful 2 months ago
This has been flagged as spam show
@jakspyder I am not confused about this logic. I've just mentioned that in that exact tutorial, in that exact example, this thing was made in the way I've described, that's all. It was not a question and misunderstanding, so stop answering me, especially with that dumb stuff like TheSandvichTrials wrote.
Everlovingful 2 months ago
@Everlovingful Yeah sure if you do something wrong, the outcome is wrong.
TheSandvichTrials 2 months ago in playlist Java Programming Tutorials
Have a 7 1/2 hour trip to gmas for thanksgiving... what am i doing? watching bucky :)
blamsam001 3 months ago in playlist Java Programming Tutorials
This has been flagged as spam show
1. Turn on the subtitles
2. Go to 4:00
:D
TheOnlyGamingGamer 3 months ago in playlist More videos from thenewboston
Comment removed
TheDemonStr 3 months ago
1. Turn on the subtitles
2. Go to 4:00
:D
runika1000 3 months ago 65
@runika1000 masturbation store :)
TheLazus 3 months ago 3
@runika1000
Good translation skill. (I mean google)
athrun200 2 months ago
@runika1000 :)
Wow! this is very philosophic quote "If you wanna be dumb but, in a masturbation store!"
TheCanavarTv 1 month ago 2
@runika1000 4:25 is slightly funny too :P
FunFasit 2 weeks ago
I really like these tutorials, you're kinda funny and you do a good job, hopefully I'll be a Java programmer by New Year's Eve.
MineCrafterBrad 3 months ago
Comment removed
TheDemonStr 3 months ago
Comment removed
MrEmil20 3 months ago
@TheDemonStr I have made a program that can calculate that.
MrEmil20 3 months ago
I cant figure out what i should write if i want to be able to first type in the age, and then get the answer. Ive imported the scanner, i wrote: Scanner age = new Scanner(System.in); and after that: age.nextLine(); when i write the if statement, using the variable age, it doesn't work? :( What have i donw wrong? help please!
DJafferiK 3 months ago
test other variables if you want to be dumbbb lol
pennywise609 3 months ago
I'm confused now.... why don't you need the curly braces anymore?
SPlRO 3 months ago in playlist More videos from thenewboston
@SPlRO If the if statement is one line, you dont need a curly brace. The same applies to else statements. But, the only exception is in nested if statements. you can have
if (x>6)
if (x>7)
print..dsdfghsflgjhdfgh
else
printaksdfhlks
else
print skgljhsaklgj
without any curly braces needed
888chilly 3 months ago in playlist Java Programming Tutorials
@SPlRO curly braces are for organizational purposes... Very good to get used to because when you get farther in its hard to keep track of what is inside of what.. As well as nesting statements..
onelerv1 3 months ago in playlist More videos from thenewboston
lol 4:02 click transcribe audio :D
on masturbation store on and elsif same and how to use in java programming
N1gh7Sh4d3 4 months ago
@N1gh7Sh4d3 LOL and at 4:24 :
so they get a russion on makeshift security men share of
N1gh7Sh4d3 4 months ago
understood it finally thx
PopulardayOfApril 4 months ago
I like how the views slowly dimish the further along I get.
thisisjustplainstupi 4 months ago in playlist More videos from thenewboston 7
0:27 I thought you needed curly brackets to make an if statement? :O
afferik 4 months ago
@afferik You do but i think his recording system is glitching
PWNR1234 4 months ago in playlist Java Programming Tutorials
@PWNR1234
You don't really need (at least not for these simple conditions). But once the conditions become many and comprehensive, it gets much more organized and structured with curly brackets, and I believe in some cases you'll actually get errors without them. not sure tho ;)
7LFproductions 4 months ago
@7LFproductions
Ok all three of you I'm going to clear up the misunderstanding. When you have 1 action inside the if statement, curly braces are NOT necessary. However, when you want multiple actions inside the if statement, you have to use curly braces. If you don't, the program probably will not get an error, but the 2nd, 3rd, 4th, etc. actions will perform even if the if condition is false, because they are not part of the whole if this then do that thing.
pengro7 4 months ago in playlist Java Programming Tutorials
How does the else if statement vary from a switch statement?
bluestreak711 4 months ago
@bluestreak711 with an else if statement you can make like this:
int age = 55
int boys = 23
if (age <= 60)
System.out.println("Too young!");
elseif (boys == 23) then
System.out.println("Too many boys!");
with an switch statement you cant check if any other variable is something, switch statement has a certain variable
PopulardayOfApril 4 months ago
when i was taught programming in the beginning , else if statements we strongly discouraged and having only 2 conditions with nested if statements were widely used.. I still use this principle to this day! sometimes when im working on a larger project and feel lazy will i create more than 2 conditions using the else if statements :P oh how programming has evolved!
chrisykite 4 months ago
i dont really see the use of this one...you can simply type IF again instead of else if and you will get the same results =/
ChrisTheBest1992 5 months ago
@ChrisTheBest1992 it is considered good syntax to use else if statements because on a larger scale a program will run more efficiently or quicker if you use if/else rather than seperate if statements.
fadsgfjkaslhfddddddd 4 months ago in playlist Java Programming Tutorials
i just saw there are 86 tutorials o.O SWEEEEET!
DJafferiK 5 months ago 4
Awesome tutorial but wouldnt it make more sense if you could enter ur age and after that it told you "youre in your 40s" or whatever? (and i know, there is another tutorial on how to do that stuff)
DJafferiK 5 months ago
Getting there...
paulceltics 5 months ago
why can't you put just a buch of if's?
soldado1997 5 months ago in playlist Java Programming Tutorials
@soldado1997 that why he's explaining this becus it saves you time doing this
and its more efficient
15ceder 5 months ago
@soldado1997 to make it less confusing
gameking008 5 months ago in playlist More videos from thenewboston
@soldado1997 Because if you just put a bunch of if's, it'll test each one and if you put one if and all the following ones as else if, once a test comes out positive, it doesn't go on to check the rest of the tests!
abhik9ray 5 months ago in playlist Java Programming Tutorials
@thenewboston Thank you, You have made learning java allot easier! :)
Curtis1509 6 months ago
This has been flagged as spam show
import java.util.Scanner;
public class ifthenelse {
public static void main(String[] args){ Scanner ages = new Scanner(System.in); int age = 0; System.out.println("Enter your age here"); age = ages.nextInt(); if (age > 17) System.out.println("You are " + age + "yrs old, access granted!"); else System.out.println("You are to young, you are: " + age);
}
}
Curtis1509 6 months ago
Comment removed
Curtis1509 6 months ago
Couldn't you just use a 'switch' statement for this?
Jonyinc 6 months ago
@Jonyinc ya but he is teaching else if so thats why.
lpguitarist06 6 months ago in playlist Java Tutorial (thenewboston AKA Bucky)
Ah, so else if is the same as writing an if statement inside another one?
kmncztms 6 months ago
@kmncztms Yup, just cleaner and easier
davak72 6 months ago
Im watching this, But I'm really only on episode 3, Waiting for eclipse to download XD
Allenmarxchannel 6 months ago 74
@Allenmarxchannel same here ^^
Genuigr 3 months ago in playlist Java Programming Tutorials
@Allenmarxchannel I think you won't learn anything about it! :D
persiaTUT 1 month ago
wouldn't this work if you just used a switch statement with mutiple cases?
doody884 6 months ago
@doody884 yes. But he is teaching else if statements...
GPoliko 6 months ago
Ha! I made bmi calc when he teached math and if statements, this should be teached earlier 'cause this is important. Also remember to apply the contents of these tutorials and you'll discover more and most importantly learn.
toponen123 6 months ago in playlist Java Programming Tutorials
is this same as VBS?
i m learning vbs and i wanna know it?
thank you
the147break 7 months ago in playlist programowanie
@the147break its not but its kind of similar
SilentDesease 6 months ago
portal 2 "Testing for science!"
TheDorob121 7 months ago
Oh god. Still 60 more to go! T.T
PinkyTheTroll 7 months ago
@PinkyTheTroll yah in 8 episodes, aye aye aye, 68 eoisides DX
carrots087 7 months ago
Aren't "nested if statements" (the previous tutorial) and "else if statements" the same thing? The only difference I can see is that for "else if", you put "if" BESIDE "else" rather than on a new line.
MisterM2402 7 months ago
@MisterM2402 the nested if statements will make it print two lines (the initial statement then the nested one) The else if only prints whatever line applys
Jasonhalo0 7 months ago
the heck happened to the brackets in the if statements!!
jrobenson1 7 months ago
whats the difference between the switch command?
Ganokbcn 7 months ago
he needs to learn the shortcuts for copy and paste
Gavin3284 8 months ago
ok so i was going smoothly through all of his tutorials until his brackets started ending up farther to the right then mine...idk wth has happened but now my code gets all messed up :/ help plz...
t89pepper 8 months ago
@t89pepper What do you mean by his brackets started ending up farther to the right then yours? If you mean that some of his code seems to be more to the right than yours is, that doesn't really matter. What matters is that the syntax is correct. Make sure all of the curly braces are properly opened and closed, and that you have semi-colons where there should be, and it should work fine.
otakughost 8 months ago
you know you can just ctrl+c to copy and ctrl+v to paste?
hcbtGaming 8 months ago
@hcbtGaming oh ya lol
tech0dude123 8 months ago in playlist java the new boston
19 down... 68 more to go.. :) thanks Bucky.
PS3GAMEPWNERZ 8 months ago 60
Whats the difference here between switch and this?
98Tul 8 months ago
@98Tul else if is more flexible and can be > < whatever rather then only ==
kickman199811011 8 months ago
You make Java programming look so easy.
kickman199811011 8 months ago
hahaha this is so easy :}
monkey64cow 9 months ago
any reason why you'd choose to use massed else-if statements over a switch statement in an IRL case?
LeftRight1511 9 months ago
@LeftRight1511 Can you use Chars and Strings in switch statements?
LyriiczBoii 8 months ago
@LyriiczBoii yup
LeftRight1511 8 months ago
keep the good work... love your tutorials.
TheSh4go2 9 months ago
Hey guys answer me please. How do I use "if" statement from user input. For example. System.out.println("Are you a MALE or a FEMALE, type f/m: "); , I want to use an IF statement that is going to react based on what I type to the program (f, or m) Please help thanks
fearlessftw 9 months ago
@fearlessftw Make a variable(string or char it doesnt matter) to save the information you are going to scan. after that use of the if statement with the variable you just created... my suggestion use an elseif in case the person make a mistake and type something different from M or F
TheSh4go2 9 months ago
This has been flagged as spam show
was actually told that any java class must start with an UPPERCASE letter, e.g class Maths. 'M' is capital, but yours contradicts.
Dimorez 9 months ago
Comment removed
Dimorez 9 months ago
"if you wanna be dumb...but uhm" x)
EckoFresh92 9 months ago
its always funny how that in a series of tutorials the people viewing get less and less as the lessons go on
JamesCalex 9 months ago
@JamesCalex
The last java video has only 300+ views, and its been up since last year.
Jacobgamesandreviews 9 months ago
@JamesCalex true programmer get reviled. And idiots who were just along on the ride to "prove to them selves" that they can learn java quit. caz they can't processes the awsomeness of java :D
toy741life 9 months ago
@JamesCalex Exactly. That's what I am noticing..Viewers go down when tutorial goes up. All losers.
cmdahal 9 months ago
hi is that must u have to end with single Else what happen if we put elseif in our last else
MrKirandp 9 months ago
this is the same as a switch statement
TheWondererMan 10 months ago
@TheWondererMan no no no no this is completly different thing. Switch statement is for exact numbers (if im not frong) and if is more for not so exact numbers. Switch for 1,2,3,4,5,6... and if for numbers between 2 numbers. And that should have made sense..
zedo28 10 months ago
@zedo28 Can't If statments be also used for text input?
ProverHeartAnnalia 9 months ago in playlist Bucky's Java Tutorial
@ProverHeartAnnalia Yeah.. I personally use if even if switch can be placed
zedo28 9 months ago
Bucky, you are so great, i've looked for so many tutorials but every tutorial sucks, but if i look at your, it looks so simple!
thanks alot man, much appreciated!!!!!!!!!!!!!!!!!!!!
rickvangils100 11 months ago 3
why dont you need {}'s for this one as opposed to single if statements?
thedeathofchrispalko 11 months ago 3
goooooooooooood
ReKardooo1 11 months ago
do you have tutorial for JOptionPane?
akolang42 11 months ago
coming from python we use elif for else if. for java does else if have to be between if and else? or can it be used like python one if and the rest elif?
Dusty2084 11 months ago
@Dusty2084 You don't need to have the last "else" in it but you need the first "if"
GeekyMe97 11 months ago
It's funny how after each video, the number of views decrease...shows how much dedication and determination people have for the language...quitters! =P
Sabo3113 11 months ago
thanks for these vids
Thisisloco1 11 months ago
3:57 lol " If you wanna be dumb but..."
tutornomnum 11 months ago
You sir, should sell this stuff on DVDs!
MrBlockersPro 11 months ago
There are a ton of these things: If statements, switch statements, nested if statements, else if statements...
I think you can make the same program with any of them, but some are faster. So far I feel nested ifs are a little too confusing for my taste, and switch statements seem to work perfectly fine for most things.
utupoe111 11 months ago
Comment removed
MrHowToDoIt 1 year ago
Does anyone know how to use a string imported from the scanner in a switch/if/else if statement. I really need to be able to do that for a program im working on.
NEDinACTION 1 year ago
MrHowToDoIt 1 year ago
Thanks for making these videos, man.
Oaklio 1 year ago
so, else if statment are kinda like switch statement?
lefthanded1995 1 year ago
Cool. I am a young buck!
DexManley0 1 year ago
bucky the java slayer
yemieko 1 year ago
else if statements > if else statments .... else if statements are so much easier to do.
TheSw1fty 1 year ago
can u help me cuz i want age = user input how do i do that?
maffiajer 1 year ago
6 people missed the Like button :P
guitarhero7946 1 year ago
If I recall it correctly, didn't the past videos use: main(String args[]) while this one uses main(String[] args) lol... what's the diff?
dmartinng 1 year ago
If I recall it correctly, didn't the pass videos use: main(String args[]) while this one uses main(String[] args) lol... what's the diff?
dmartinng 1 year ago
Guys, just so you know what you learned today here's a quick sumaray. Else if statements are convieneint because it saves you the trouble of making multiple if statements which reuire a new set of braces each time you type them. Else if statements are more like switch statements-easy to type, simple, and neat-, but they are not nearly as specific as switch statements because you can choose from a wide range of numbers. Switch statements can only select one number at a time.
Fusionbirds101 1 year ago 3
older people must hate you xD
mehfuckit 1 year ago
@TheGreekSkater The else if-statement is like the else-statement but with a condition. So if the if-statement before an else if-statement is false but else if is true the code in else if will be executed. If they're both true only the if-statement will be executed.
If you use two if-statements instead both will be executed if they're both true.
oggzter93 1 year ago
This has been flagged as spam show
If you really want to marry an Latino women come to us rockmycity.info
honsusando 1 year ago
mikeyb2k9 1 year ago
"Syntax error on token "else", delete this token" this is what i get when i put the else statement under the else if.
Gmod4ThaWin 1 year ago
whats the difference between writing "if" or "else if"
you can just write another "if"
TheGreekSkater 1 year ago
Quick question, using a switch statement would do the same, correct?
indieology 1 year ago
@indieology I dont think you can test if a number is between a certain range with a switch, e.g (age >=50 && <60)
I might be wrong, Just tried it and it didnt work, someone can correct me if Im wrong
ST34LTH1 1 year ago
@ST34LTH1 You just have to add age before <60, so you always have to say what you want to compare with what.
oggzter93 1 year ago
the braces can be omitted if no multiple actions will be executed if you will only print a string, you may not include a brace as long it is included in the if or else statement :)
nheyo19 1 year ago
Thank you so much : ) I have a Computer Programing Final Exam tomorrow and I never really understood if/else statements. Great for review :D
iLogan13 1 year ago
so you dont really need curly brakets or what ever for your code?
example:
if(whatever) { System.out.
}else{ System.out.
you can do that with out the brakets?
so whats the point of sometimes putting them and sometimes not???
AliahBishr 1 year ago 3
@AliahBishr if You dont put brackets You can only add one next line, if you put two or more it will prompt an error, so it safer and cleaner to put those bracketes every time imo, e.g. when you want to put another line of code later on
mufaPufaDha 1 year ago 18
@mufaPufaDha Oh ok lol thanks
AliahBishr 1 year ago
@AliahBishr the only two solution i came up with is that braces consume time when computer is reading them so first programmers decided to gain some time and exclude braces from one line statements when it was possible, but thats pretty stupid imho... OR, they have small terminals that displayed only like 24 lines of code which is more possible i think. "(...)By bracing every if, else, while, etc.—even single-line conditionals— insertion of a new line of code anywhere is always "safe"."
mufaPufaDha 1 year ago 11
@mufaPufaDha Ok :) thanks
So its better that I use the braces always instead of leaving them out sometimes right?
thanks for the tip..highly appreciated
AliahBishr 1 year ago
Bucky, you rock! Just one comment, your previous 'IF' tut used curly braces around the 'IF' and corresponding 'ELSE' statements, in this tutorial you omit them; is it better to do it with or without curly braces?
vinchisel 1 year ago
@vinchisel If you need more than 1 line of code in your if/else/else if statements, use curly braces. If you only need 1 line, it doesn't really matter.
lodman97 1 year ago
instead of
int age=60
type this .
Scanner reed=new Scanner(System.in);
int age;
System.out.println("enter your age");
age=reed.nextInt();
now you are able to type your age and run your programme perfectly
Islamproof 1 year ago
wait what?? you didnt even put brackets on those and they worked
uthuh 1 year ago
Eclipse is telling me "Syntax error on token "else" delete this token."
I'm confused. :/
class cake { public static void main(String[] args) { int age = 55; if(age > 60); System.out.println("You're a senior citizen."); else System.out.println("You're a young buck."); }
}
datshortkid1 1 year ago
@datshortkid1
Never mind. I had to remove a ; lol
datshortkid1 1 year ago