Jumat, 25 Maret 2011

for dan array

Memakai for

import java.util.Scanner;

public class dataku {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.print("Masukan jumlah data =");
int data = input.nextInt();

for(int i=1;i<=data;i++){
System.out.print("data = ");
// int data1=input.next();

String data1 = input.next();
String data2 = input.next();
data2 = data2 +"" +data1;
System.out.println("Hasil : " +data2);
}
}






Memakai array

import java.util.Scanner;

public class NewClass {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
int n;
String[] data = new String[10];
System.out.print("Masukan jumlah data = ");
n = input.nextInt();
for(int i=1;i<=n;i++){
System.out.print("data ke "+i +"=");
data[i] = input.next();
}
String gabung=" ";
for(int i=1;i<=n;i++){
gabung = gabung +data[i];
System.out.print("hasil ="+gabung);

}
}}

Tidak ada komentar:

Posting Komentar

chatme


ShoutMix chat widget