Program Ascending dan Descending

Pada kesempatan kali ini kita akan membahas tentang Program Ascending dan Descending . . .

Berikut ini adalah source code nya:

package tugas2;

import javax.swing.JOptionPane;

ublic class AscendingDescending {

public static void main(String[] args) {

String inputAwal = JOptionPane.showInputDialog(“Masukkan nilai awal : “);

int Awal = Integer.parseInt(inputAwal);

String inputAkhir = JOptionPane.showInputDialog(“Masukkan nilai akhir : “);

int Akhir = Integer.parseInt(inputAkhir);

if (Awal<Akhir){

System.out.print(“Ascending : “);

for (int i=Awal; i<=Akhir; i++)

System.out.print(i+” “);

System.out.println(“\n”);

System.out.print(“Descending : “);

for (int j=Akhir; j>=Awal; j–)

System.out.print(j+” “);}

else

if (Awal>Akhir){

System.out.print(“Ascending : “);

for (int i=Akhir; i<=Awal; i++)

System.out.print(i+” “);

System.out.println(“\n”);

System.out.print(“Descending : “);

for (int j=Awal; j>=Akhir; j–)

System.out.print(j+” “);}

}

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s