public class NewClass {
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();
String data3 = input.next();
String gabung = "";
gabung = data1 +"" +data2 +"" +data3;
System.out.print("Hasil :"+ gabung);
}
}
}
contoh mpengulangan mengunakan array
import java.util.Scanner;
public class NewClass1 {
public static void main(String[] args){
Scanner input = new Scanner (System.in);
int n;
String [] data = new String [10];
System.out.println("masukan jumlah data");
n = input.nextInt();
for (int i=1;i<=n;i++){
System.out.println("data ke "+i+"");
data [i] = input.next();
}
String gabung = "";
for (int i=1;i<=n;i++){
gabung = gabung +""+data[i];
System.out.println("hasil = "+ gabung);
}
}
}
0 komentar:
Posting Komentar