๐Ÿ”’ 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
  • 501
    Views
  • 2
    Participants
Last reply from:
Papercut

Online now

Members online
939
Guests online
1,020
Total visitors
1,959

Forum statistics

Threads
2,276,293
Posts
28,968,990
Members
1,231,205
Latest member
SPAdma
Back
Top