Archive

Posts Tagged ‘String’

Contoh Program Array

December 31, 2009 Leave a comment

package SL275;

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author GW_SBY
*/
public class ArrayDemo {

public static void main(String[] args) {
int[] anArray; // declares an array of integers

anArray = new int[10]; // allocates memory for 10 integers

anArray[0] = 100; // initialize first element
anArray[1] = 200; // initialize second element
anArray[2] = 300; // etc.
anArray[3] = 400;
anArray[4] = 500;
anArray[5] = 600;
anArray[6] = 700;
anArray[7] = 800;
anArray[8] = 900;
anArray[9] = 1000;

System.out.println(“Element at index 0: ” + anArray[0]);
System.out.println(“Element at index 1: ” + anArray[1]);
System.out.println(“Element at index 2: ” + anArray[2]);
System.out.println(“Element at index 3: ” + anArray[3]);
System.out.println(“Element at index 4: ” + anArray[4]);
System.out.println(“Element at index 5: ” + anArray[5]);
System.out.println(“Element at index 6: ” + anArray[6]);
System.out.println(“Element at index 7: ” + anArray[7]);
System.out.println(“Element at index 8: ” + anArray[8]);
System.out.println(“Element at index 9: ” + anArray[9]);
}
}

Hitung pangkat sebuah nilai dengan For Loop

December 31, 2009 Leave a comment

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package TugasModule4;

/**
*
* @author Arin
*/
public class PerpangkatanForLoop {
public static void main(String[] args) {
// TODO code application logic here
int nomor ;
int batas = 100;

for ( nomor = 0; nomor < batas; nomor++) {
System.out.println(nomor * nomor + ” adalah perpangkatan dari ” + nomor);
}
}
}

Hitung pangkat sebuah nilai dengan Do While

December 31, 2009 Leave a comment

package TugasModule4;

/**
*
* @author Arin
*/
public class PerpangkatanDoWhile {

public static void main(String[] args) {
// TODO code application logic here
int nomor = 0;
int batas = 100;

do {
System.out.println(nomor * nomor + ” adalah perpangkatan dari ” + nomor);
nomor++;
} while (nomor <= batas);
}
}

Membaca Bilangan Dengan Switch

December 30, 2009 Leave a comment

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package TugasModule4;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
*
* @author Arin
*/
public class MembacaBilanganSwitch {

public static void main(String[] args) {
BufferedReader dataIn = new BufferedReader(new InputStreamReader(System.in));
String a = “”;
System.out.print(“Inputkan sebuah nilai = “);
Read more…

Membaca Bilangan Dengan If Else

December 30, 2009 Leave a comment

Berikut contoh program membaca bilangan dengan struktur perulangan If Else

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package TugasModule4;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
*
* @author Arin
*/
public class MembacaBilanganIfElse {
public static void main(String[] args) {
//int a = 25;
BufferedReader dataIn = new BufferedReader(new InputStreamReader(System.in));
String a = “”;
System.out.print(“Inputkan sebuah nilai = “);
Read more…

Follow

Get every new post delivered to your Inbox.