🔒 Closed Java output

Status
Not open for further replies.

Papercut

Forum Veteran
help pano po makuha yung last na na comma sa output? baka ma wrong ako , ito po code ko



/* Using while, do-while, or for loop, write a program that will produce this sequence of numbers:
1, 5, 2, 4, 3, 3, 4, 2, 5, 1 */

public class Sequence {
public static void main(String args[]) {
int n = 6;

for(int i = 1; i<n; ) {
int a= n - i;
System.out.print(i +", "+ a+", ");
i++;
}
}
}

Screenshot (9)_LI.jpg
 
Java:
public class Sequence {
public static void main(String args[]) {
    int n = 6;
        for(int i = 1; i < n;) {
            int a = n - i;
            if(i == n - 1)
                System.out.print(i +", "+ a);
            else
                System.out.print(i + ", "+ a + ", ");
            i++;
        }
    }
}

OR THIS

public class Sequence {
public static void main(String args[]) {
    int n = 5;
        for(int i = 1; i <= n;) {
            int a = n - i;
            if(i == n )
                System.out.print(i +", "+ a);
            else
                System.out.print(i + ", "+ a + ", ");
            i++;
        }
    }
}
 
Java:
public class Sequence {
public static void main(String args[]) {
    int n = 6;
        for(int i = 1; i < n;) {
            int a = n - i;
            if(i == n - 1)
                System.out.print(i +", "+ a);
            else
                System.out.print(i + ", "+ a + ", ");
            i++;
        }
    }
}

OR THIS

public class Sequence {
public static void main(String args[]) {
    int n = 5;
        for(int i = 1; i <= n;) {
            int a = n - i;
            if(i == n )
                System.out.print(i +", "+ a);
            else
                System.out.print(i + ", "+ a + ", ");
            i++;
        }
    }
}
Salamat po❤️
 
Status
Not open for further replies.

About this Thread

  • 2
    Replies
  • 507
    Views
  • 2
    Participants
Last reply from:
Papercut

Trending Topics

Online now

Members online
339
Guests online
837
Total visitors
1,176

Forum statistics

Threads
2,286,938
Posts
29,041,295
Members
1,217,273
Latest member
Ko11ya
Back
Top