public class JavaApplication1 { 
    public static void main(String[] args) {
    for (int i = 5 < = 100; 1 + = 5){
System.out.print(i);
if (i <100){
System.out.print(",");
}
}
}
}

Recommended Answers

All 5 Replies

"It's not working" is completely useless. Describe how it's not working if you want better help. But I'll point out some obvious flaws in the code:

for (int i = 5 < = 100; 1 + = 5){

This line is all borked up. A for loop has three clauses separated by a semicolon and you only have one semicolon rather than two. <= is a single operator, and whitespace between the two parts will cause a syntax error. += is a single operator, separating whitespace won't work. 1 += 5 is nonsensical, you probably meant i += 5. The line should look like this:

for (int i = 5; i <= 100; i += 5) {

perhaps you are new to java because you don't even know how to use for loop :
The correct syntax is:

for (initialization; termination;  increment)
{
    statement(s)
}

By changing the syntax your code is working correctly.

 class JavaApplication2 { 
    public static void main(String[] args) {
    for (int i =5; i <= 100; i ++){
System.out.print(i);
if (i <100){
System.out.print(",");
}
}
}
}

Do tell me if you need any more clarification.

commented: I like this clear and concise explanation. +0

now how do i turn the output backwards like this

100 95 90 85 80 75 70.........10 5

thanks

Reverse the loop to count down from 100:

for (int i = 100; i >= 5; i -= 5) {
    System.out.print(i);

    if (i > 5) {
        System.out.print(",");
    }
}

ehm .. why would you post a link like that? far as I can see, it's hardly informative, you're just spreading a link to your own page.

also, I would update, or correct, your explanations a bit.
1. an array is not a collection, don't call it that.
2. your explanation how to organize in packages kind of says that every .jar is built around one particular package, which isn't at all true.
packages group classes of a similar type, with similar functionalities, for instance, all DAO's in one package, all screens in another package, all exceptions in one package, ...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.