0% found this document useful (0 votes)
2 views

java

Praktik java

Uploaded by

Nur Ahla
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

java

Praktik java

Uploaded by

Nur Ahla
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

/*

* To change this license header, choose License Headers in Project Properties.


* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package praktik_stack;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author user
*/
public class Stack3 {
private List<Object> list=new ArrayList<Object>();
private int currentIndex=-1;
int max=5;

public void push(Object object){


list.add(object);
currentIndex++;
}

public Object pop(){


Object object=list.remove(currentIndex);
currentIndex--;
return object;
}
public int count (){
return list.size();
}
public Object peek(){
return list.get(currentIndex);
}
public void clear(){
list.clear();
currentIndex=-1;
}

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package praktik_stack;

import java.util.Scanner;

/**
*
* @author user
*/
public class Tgs_stack {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Stack3 bill = new Stack3();
String kalimat =" ";
String akhir= " ";
String Teks = " ";

System.out.println("Input = ");
Scanner scan = new Scanner (System.in);
kalimat = scan.nextLine();
Object kata = kalimat.split("");
bill.push(kata);

String angka = kalimat.replaceAll("[^0-9.]","");

int balik = angka.length();


for (int i = balik-1; i>=0; i--){
akhir = akhir+angka.charAt(i);
}
System.out.println("output : "+akhir);
}
}
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<select id="mySelect">
<option value ="1">pilihan 1</option>
<option value ="2">pilihan 2</option>
<option value ="3">pilihan 3</option>
</select>

<button onClick="getNilai()">Ambil Nilai</button>


<p id="hasil"></p>

<script>
function getNilai(){
var x = document.getElementById("mySelect").value;
//console.log(x);
document.getElementById("hasil").innerHTML = x;
}
</script>
</body>

<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<select id="pilihan">
<option value ="1">keliling persegi</option>
<option value ="2">luas persegi</option>
</select>

<input type="text" id="isi">meter


<button onClick ="hitungPersegi()">hitung hasil</button>
<div id="hasil"></div>

<script>
function hitungPersegi(){
var x = document.getElementById("pilihan").value;
var isi = document.getElementById("isi").value;
switch(x) {
case "1":
document.getById("hasil").innerHTML = isi*4;
break:

case "2":
document.getById("hasil").innerHTML = isi*isi;
break:
}
}
</script>
</body>

You might also like