how can I do if else statement im just a starter? | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 3

how can I do if else statement im just a starter?

what can I do with the if-else statement when i program? if (statement) { System.out.println("__"); } else { Statement } is it wrong??????

25th Jan 2018, 10:59 AM
Charlotte Salunoy
Charlotte Salunoy - avatar
2 ответов
+ 18
suppose u want to output something different if it condition goes false //for example u want to output whether a number is odd or even then , u will write if (n%2==0) {System.out.print("even");} else {System.out.print("false");}
25th Jan 2018, 11:28 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
0
suppose u want to take an input of 2 no. and print the greater one hence u have to use the if else statement.. in the if(here u have to the condition in parenthesis) if it is true then the program is executed for the resulting if conditions else it proceeds via else.. example:::::: #include<iostrem> using namespace std; int main() { int x, y ; //assuming x and y are not equal. cout<< "Enter 2 numbers : " ; cin >> x >> y ; if (x>y) //condition for if cout<< x ; else cout<< y ; //when the condition for if is not true this is followed. return 0 ; } // when the if or else algorithms(steps when the condition is true) are single line then u have to put no braces but if they have multiple steps then u have to write the steps in curly braces { like this } Thats all...
26th Jan 2018, 4:46 PM
vickyvirus258