1.Listing Deret lurus
import javax.swing.JOptionPane;
public class deret{
public static void main(String[]args){
String Str = null;
Str = JOptionPane.showInputDialog ("Masukkan nilai = ");
int nilai = Integer.parseInt(Str);
for (int i=1; i<=nilai; i++){
for (int j=1; j<=i; j++){
System.out.print(j);
System.out.println("");
}
}
}
}
2.Listing Deret segitiga
import javax.swing.JOptionPane;
public class deret1{
public static void main(String[]args){
String Str = null;
Str = JOptionPane.showInputDialog ("Masukkan nilai = ");
int nilai = Integer.parseInt(Str);
for (int i=1; i<=nilai; i++){
for (int j=1; j<=i; j++){
System.out.print(j);}
System.out.println("");}
}
}
0 komentar:
Posting Komentar