Jump to content

Why isnt this Java code working?

I need to set the value of the boolean isComplete to true, but i cannot do that because it gives me a error, help?

 

 

 

Here it is 

 

 

 

 

 

 

 

public class Generalizations {
public static void main(String[] args) {
 
 
boolean isComplete; true 
int awesomeLevel;
int epicLevel;
/*System.out.println(epicLevel);*/
    // This is a comment, EpicKneusje put all by himself /    
 
 
}
}
Edited by EpicKneusje

Please, follow your own posts and mention me in comments, otherwise i won't be able to help you.

Daily OS: OpenBSD -current

Link to comment
https://linustechtips.com/topic/466947-why-isnt-this-java-code-working/
Share on other sites

Link to post
Share on other sites

public class Generalizations {    public static void main(String[] args) {        boolean isComplete;        true int awesomeLevel;        int epicLevel;         /*System.out.println(epicLevel);*/ // This is a comment, EpicKneusje put all by himself     } }

should be:

public class Generalizations {    public static void main(String[] args) {        boolean isComplete = true;          int awesomeLevel;   // not initialized        int epicLevel;      // *as pointed out by msvelev, this needs to be initialized for the next line, otherwise it won't compile.        System.out.println(epicLevel);     } }

It makes it a lot easier for others to read if you properly indent and post code with the code formatter (the blue <> symbol in the forum editor).

CPU: i7-4790K --- HEATSINK: NZXT Kraken X61 --- MOBO: Asus Z97-A --- GPU: GTX 970 Strix --- RAM: 16GB ADATA XPG --- SSD: 512GB MX100 | 256GB BX200 HDD: 1TB WD Black --- PSU: EVGA SuperNova G2 --- CASE: NZXT H440 --- DISPLAY3 x Dell U2414H --- KEYBOARD: Pok3r (Clears) --- MOUSE: Logitech G Pro --- OS: Windows 10

Link to post
Share on other sites

public class Generalizations {    public static void main(String[] args) {        boolean isComplete = true;          int awesomeLevel;   // not initialized        int epicLevel;      // this needs to be initialized or else the next line will print null        System.out.println(epicLevel);     } }It makes it a lot easier for others to read if you properly indent and post code with the code formatter (the blue <> symbol in the forum editor).

Primitive types cannot be null. This won't even compile. If it was a field instead of local variable it would've gotten the default value of 0.

CPU: Ryzen 3 3600 | GPU: Gigabite GTX 1660 super | Motherboard: MSI Mortar MAX | RAM: G Skill Trident Z 3200 (2x8GB) | Case: Cooler Master Q300L | Storage: Samsung 970 EVO 250G + Samsung 860 Evo 1TB | PSU: Corsair RM650x | Displays: LG 27'' G-Sync compatible 144hz 1080p | Cooling: NH U12S black | Keyboard: Logitech G512 carbon | Mouse: Logitech g900 

Link to post
Share on other sites

I can't see the code.

 

EDIT : isComplete = true; 

I don't do Java and I saw that ^^

 

Thank you all, im quite new to coding and i thought java would be the best bet since its quite easy. Thanks!

Just remember these ; are to end sentences/commands.

"We're all in this together, might as well be friends" Tom, Toonami.

 

mini eLiXiVy: my open source 65% mechanical PCB, a build log, PCB anatomy and discussing open source licenses: https://linustechtips.com/topic/1366493-elixivy-a-65-mechanical-keyboard-build-log-pcb-anatomy-and-how-i-open-sourced-this-project/

 

mini_cardboard: a 4% keyboard build log and how keyboards workhttps://linustechtips.com/topic/1328547-mini_cardboard-a-4-keyboard-build-log-and-how-keyboards-work/

Link to post
Share on other sites

I don't do Java and I saw that ^^

 

Just remember these ; are to end sentences/commands.

Thanks bud, I just finished the course tho, do you maybe know other languages?

Please, follow your own posts and mention me in comments, otherwise i won't be able to help you.

Daily OS: OpenBSD -current

Link to post
Share on other sites

Thanks bud, I just finished the course tho, do you maybe know other languages?

You could try doing some Javascript (not related to Java) which is a programming language used on websites. (Alongside HTML and CSS)

"We're all in this together, might as well be friends" Tom, Toonami.

 

mini eLiXiVy: my open source 65% mechanical PCB, a build log, PCB anatomy and discussing open source licenses: https://linustechtips.com/topic/1366493-elixivy-a-65-mechanical-keyboard-build-log-pcb-anatomy-and-how-i-open-sourced-this-project/

 

mini_cardboard: a 4% keyboard build log and how keyboards workhttps://linustechtips.com/topic/1328547-mini_cardboard-a-4-keyboard-build-log-and-how-keyboards-work/

Link to post
Share on other sites

in c code is way easier to read imo.

i would def. go with that since your new to coding.

it may be a bit harder, now that you started with java but it will pay of i think.

just started the PHP course, wish me luck xD

Please, follow your own posts and mention me in comments, otherwise i won't be able to help you.

Daily OS: OpenBSD -current

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×