hint:
Sa array, you access values by their INDEX....right?
- from index ZERO pataas for Asccending
- from HIGHEST index down to ZERO for Descending
- from middle down to zero...or middle up to highest index
Halimbawa:
[5,1,4,2,3]
index 0 = 5
index 1 = 1
index 2 = 4
index 3 = 2
index 4 = 3
import java.util.Scanner;
public class AlternativeReverse {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Enter Number: ");
int num = in.nextInt();
int t_num = num;
for (int i = 1; i <= num; i++) {
System.out.printf("%-5d - %5d %n", t_num, i);
t_num--;
}
}
}
hint:
Sa array, you access values by their INDEX....right?
- from index ZERO pataas for Asccending
- from HIGHEST index down to ZERO for Descending
- from middle down to zero...or middle up to highest index
Halimbawa:
[5,1,4,2,3]
index 0 = 5
index 1 = 1
index 2 = 4
index 3 = 2
index 4 = 3
import java.util.Scanner;
public class AlternativeReverse {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Enter Number: ");
int num = in.nextInt();
int t_num = num;
for (int i = 1; i <= num; i++) {
System.out.printf("%-5d - %5d %n", t_num, i);
t_num--;
}
}
}
OdenDi
Mag ingat lang kasi some of us here are more generous na mag bigay ng solutions than others.
Kung gusto mo solid ang iyong knowledge, do not copy and paste solutions and be done with it.
Pag-aralan mo ang concept and then make your own (there are many ways to a solutions in programming).