What is the problem of this code in java? | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
0

What is the problem of this code in java?

public class Project { public static void main(String[] args) { int a = 5; int b = a++; int c = b++; System.out.printIn(c); } }

9th Jul 2016, 7:54 AM
Very hard!
Very hard! - avatar
6 ответов
0
because you are using post increment operator it adds 1 to a after the statement int b = a++; if you want it to work use pre increment operator that's ++a
9th Jul 2016, 8:02 AM
Ore Falomo
Ore Falomo - avatar
0
Na I know that but This program isnt print variable of c and alert which non-sense error
9th Jul 2016, 11:29 AM
Very hard!
Very hard! - avatar
0
/*This code too*/ public class Project { public static void main(String[] args) { int c = 6; System.out.printIn(c); } } /*When I try it's error so I must use "System.out.print"*/
9th Jul 2016, 11:32 AM
Very hard!
Very hard! - avatar
0
output is 5 because of post increment
9th Jul 2016, 6:37 PM
Anup Shetty
0
yes use pre increment operator.that is b=++a; c=++b;
9th Jul 2016, 6:40 PM
Anup Shetty
0
I'm roger I'm roger But I mean the error is System.out.printIn function doesnt working T-T
17th Oct 2016, 12:53 PM
Very hard!
Very hard! - avatar