Skip to content

Instantly share code, notes, and snippets.

@dwiash
Created January 21, 2010 10:24
Show Gist options
  • Save dwiash/282711 to your computer and use it in GitHub Desktop.
Save dwiash/282711 to your computer and use it in GitHub Desktop.
PETUNJUK:
data inputan terletak pada file input.txt
data inputan harus menggunakan format yang telah ditentukan.
formatnya adalah seperti berikut:
6
4
1 2 3 2 3 4
3 4 5 5 6 7
0 12 3 4 5 6
1 2 3 12 31 2
baris pertama meruapakan jumlah kolom matrix (pada contoh=6 kolom)
baris kedua merupakan jumlah baris matrix (pada contoh=4 baris)
baris selanjutnya merupakan matrix inputan
PERHATIAN, file input.txt harus berada pada folder yang sama dengan program yg telah dicompile
6
4
1 2 3 2 3 4
3 4 5 5 6 7
0 12 3 4 5 6
1 2 3 12 31 2
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
public class Main {
public static void main(String[] args) {
try {
File fileInput = new File("input.txt");
BufferedReader buffRead = null;
buffRead = new BufferedReader(new FileReader(fileInput));
int jumlahKolom = Integer.parseInt(buffRead.readLine());
int jumlahBaris = Integer.parseInt(buffRead.readLine());
String[] s = new String[jumlahKolom];
int i,j,k,l = 0;
String str = " ";
for(i=0; i<jumlahBaris; i++){
str = buffRead.readLine();
s = str.split(" ");
l = s.length;
for (j=0; j<l; j++){
k = l - j - 1;
System.out.print(s[k] + " ");
}
System.out.println("");
}
} catch (Exception ex) {
//
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment