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

Essay Program Java

Uploaded by

Andre Kusuma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Essay Program Java

Uploaded by

Andre Kusuma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Nama : Andre Kusuma Anwar

NIM : 1822496723
Kelas : Pemrograman 3 (SI171C)

Syntak :
Syntak Text :

package Strukturdata;

import java.util.Stack;

import java.util.*;

public class essay {

public static String reverse(String str) {

if (str == null || str.equals(""))

return str;

Stack<Character> stack = new Stack<Character>();

char[] ch = str.toCharArray();

for (int i = 0; i < str.length(); i++)

stack.push(ch[i]);

int k = 0;

while (!stack.isEmpty()) {

ch[k++] = stack.pop();

return String.copyValueOf(ch);

public static void main(String[] args) {

Scanner start = new Scanner(System.in);


String string;

System.out.print("Enter a string : ");

string = start.nextLine();

String str = string;

str = reverse(str);

System.out.println("Reversed: " + str);

}
HASIL :

You might also like