someone explain this code (which i mostly understand

public static void main(String[] args) { int number = 0; while (true) { number = number + 1; if (number >= 5) { break; } if (number < 5) { continue; } System.out.print(number + " "); } System.out.print(number + " "); } i get everything in this code yo but i dont understand how the output here works, and ive done a few codes like this such but what da hell
53 Replies
JavaBot
JavaBot3w ago
This post has been reserved for your question.
Hey @°~°! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
JavaBot
JavaBot3w ago
Please format your code to make it more readable. For java, it should look like this:
​`​`​`​java
public void foo() {

}
​`​`​`​
​`​`​`​java
public void foo() {

}
​`​`​`​
JavaBot
JavaBot3w ago
If you are finished with your post, please close it. If you are not, please ignore this message. Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
Itsurran
Itsurran3w ago
import java.util.Scanner;
public class Program {
public static void main(String[] main) {
Scanner scanner = new Scanner (System.in);


while (true) {

System.out.println("insert positive integers, 0 to stop");
int num = Integer.valueOf(scanner.nextLine());
if(num < 0) {
System.out.println("thats not a positive integer, try again!");
continue;
}
if (num == 0) {


break;
}
System.out.println("you put " + num);


}
System.out.println("thanks for adding!");
}
}
public class Program {
public static void main(String[] main) {
Scanner scanner = new Scanner (System.in);


while (true) {

System.out.println("insert positive integers, 0 to stop");
int num = Integer.valueOf(scanner.nextLine());
if(num < 0) {
System.out.println("thats not a positive integer, try again!");
continue;
}
if (num == 0) {


break;
}
System.out.println("you put " + num);


}
System.out.println("thanks for adding!");
}
}

look i made this code by my own but i dont get the one above
This message has been formatted automatically. You can disable this using /preferences.
°~°
°~°OP3w ago
ahhh wait i think i get it it broke at 5 since it BECAME >= 5, and instead of printing the one inside the while loop, it only printed the one outside of it since it broke eh? did i get things right or am i confused
ayylmao123xdd
ayylmao123xdd3w ago
the program stopped once it reached 5 and it printed it outside the loop
°~°
°~°OP3w ago
but the print inside the loop didnt print cos it broke before the print command correct? btw why is my name this...
dan1st
dan1st3w ago
Your name was not sufficiently pingable so the bot randomized it - I guess you have DMs disabled so you didn't get notified of that
°~°
°~°OP3w ago
no i just ignore bots
dan1st
dan1st3w ago
or that it should have told you about the name change
°~°
°~°OP3w ago
yo dan is mooc good or should i be hunry for more
JavaBot
JavaBot3w ago
If you are looking for a Java course, consider https://java-programming.mooc.fi/ which is a free course on Java Programming from the University of Helsinki. When doing the course, it is recommended to use Eclipse or IntelliJ instead of NetBeans.
dan1st
dan1st3w ago
that one?
°~°
°~°OP3w ago
14 part one
dan1st
dan1st3w ago
from what I've heard, it's quite good
°~°
°~°OP3w ago
what else did you heard thats better than quite good
dan1st
dan1st3w ago
I mean I didn't go through it by myself
°~°
°~°OP3w ago
i think i have adhd so a professor speaking just doesnt sit with me what taught u java
dan1st
dan1st3w ago
In Austria, we have certain technical schools and I did one for informatics/software development - and I also did a lot of other stuff
°~°
°~°OP3w ago
not college... im in my 2nd consecutive day of learning so idk how long this will take :roomad1: :roomad2:
dan1st
dan1st3w ago
if you really want to get good at programming, it will take time and a lot of practice
°~°
°~°OP3w ago
how much progress will i get in 4 months?
dan1st
dan1st3w ago
depends on you
°~°
°~°OP3w ago
14 hours a week 4 hours done this week, 10 hours left
dan1st
dan1st3w ago
I think it's reasonable to get the basics to a point where you can work on small projects on your own
°~°
°~°OP3w ago
but do i gotta think of my own kind of idea i did do this mini project which was very nooby
Itsurran
Itsurran3w ago
import java.util.Scanner;
public class Tax {

public static void main (String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("gifts have tax rates depending on their prices, enter your gifts price to calculate the tax rate");
double tax;
int price = Integer.valueOf(scanner.nextLine());
double finalamount;

if (price >= 5000 && price <= 25000) {
tax = (double) 100 + price * 0.08;
finalamount = (double) price + tax;
System.out.println("the gift now costs " + finalamount + " due to a " + tax + " dollar tax");
}
else if(price <= 55000) {
tax = (double) 1700 + price * 0.10;
finalamount = (double) price + tax;
System.out.println("the gift now costs " + finalamount + " due to a " + tax + " dollar tax");
}
else if(price <= 200000) {
tax = (double) 4700 + price * 0.12;
finalamount = (double) price + tax;
System.out.println("the gift now costs " + finalamount + " due to a " + tax + " dollar tax");
}
else if(price <= 1000000) {
tax = (double) 22100 + price * 0.15;
finalamount = (double) price + tax;
System.out.println("the gift now costs " + finalamount + " due to a " + tax + " dollar tax");
}
}
}
public class Tax {

public static void main (String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("gifts have tax rates depending on their prices, enter your gifts price to calculate the tax rate");
double tax;
int price = Integer.valueOf(scanner.nextLine());
double finalamount;

if (price >= 5000 && price <= 25000) {
tax = (double) 100 + price * 0.08;
finalamount = (double) price + tax;
System.out.println("the gift now costs " + finalamount + " due to a " + tax + " dollar tax");
}
else if(price <= 55000) {
tax = (double) 1700 + price * 0.10;
finalamount = (double) price + tax;
System.out.println("the gift now costs " + finalamount + " due to a " + tax + " dollar tax");
}
else if(price <= 200000) {
tax = (double) 4700 + price * 0.12;
finalamount = (double) price + tax;
System.out.println("the gift now costs " + finalamount + " due to a " + tax + " dollar tax");
}
else if(price <= 1000000) {
tax = (double) 22100 + price * 0.15;
finalamount = (double) price + tax;
System.out.println("the gift now costs " + finalamount + " due to a " + tax + " dollar tax");
}
}
}
Used no help
This message has been formatted automatically. You can disable this using /preferences.
°~°
°~°OP3w ago
i mean it was a mooc task but i took it on solo
dan1st
dan1st3w ago
yes
°~°
°~°OP3w ago
will organizations even hire me if i know java, and lets just say some other things too not just a java cert on my vc
dan1st
dan1st3w ago
When I meant working on small projects on your own, I meant that if you are interested in doing something without anyone writing a task for you, you might be able to implement it by yourself
°~°
°~°OP3w ago
got any examples well dont give me examples just tell me a project u made
dan1st
dan1st3w ago
Depends on how much you know Java, how good you can show your knowledge, your experience with libraries/frameworks/etc, where you live, the companies near you, etc
°~°
°~°OP3w ago
im willing to move out for a job
dan1st
dan1st3w ago
but it will probably be hard idk maybe a Discord bot, maybe something automating some work you have to do all the time, etc whatever is fun for you
°~°
°~°OP3w ago
well not saying im relying on java to get a job, but lets say thats the programming language part of my cv in 3 years i will have a computer science degree but i feel like those are just papers u could throw away nowadays
dan1st
dan1st3w ago
it certainly helps with getting a job getting the first job in that field is way harder without a degree
°~°
°~°OP3w ago
those roadmap youtubers are a bunch of liars ig im ok with a basic low salary job at first, not planning on getting married and im not a spender but over time i wanna make tons and send it to my family
dan1st
dan1st3w ago
I guess at least some of them do at least kinda believe in what they say
°~°
°~°OP3w ago
they make everything sound like a peace of cake
dan1st
dan1st3w ago
Is that necessarily lying?
°~°
°~°OP3w ago
"just go get a a+ and then a network+ and some wireshark then you automatically become a ceo at an airport tech branch"
dan1st
dan1st3w ago
lol
°~°
°~°OP3w ago
i mean i only started watching them when that was the only field i got accepted in at uni so i started trusting these guys with what i should do
dan1st
dan1st3w ago
I mean, they probably have an idea of what they are teaching you at uni
°~°
°~°OP3w ago
no not uni professors those youtube roadmap guys
dan1st
dan1st3w ago
yes ik
°~°
°~°OP3w ago
they made me not wanna continue uni cos how useless is that huh you just need a googly cybersecurity cert not a university degree (they are sponsored by google)
dan1st
dan1st3w ago
well, that's on you
°~°
°~°OP3w ago
its ok i just fkced up first semester the rest is going ok and im currently continuing some udemy a+ course its that bald guy jason dion
dan1st
dan1st3w ago
idk these people
°~°
°~°OP3w ago
is that also a waste of time like he explains cables for 30 mins in just section 2 let alone the other 25 sections idk what they might contain
JavaBot
JavaBot2w ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.

Did you find this page helpful?