-3
Program that implements stack to check if a given string is a Palindrome or nor.
프로그램은 사용자의 문자열을 받아 들여야하며 문자열이 스택 연산을 사용하여 역순으로 맞는지 확인해야한다 PUSH 및 POP. 여기 palindrome을 생성하는 방법을 알 수없고 스택을 출력 할 수 없다는 것을 알아낼 수 없다.
내가 지금까지 가지고있는 작업은 다음과 같습니다import java.io.*;
import java.lang.*;
import java.util.logging.Level;
import java.util.logging.Logger;
class mystack {
DataInputStream get=new DataInputStream(System.in);
int a[];
int i,top=0,n,item,out;
void getdata()
{
try
{
//user inputs to stacks
System.out.println("Enter the limit");
n=Integer.parseInt(get.readLine());
a=new int[n];
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
void push(int item)
{
if(top==n)
{
System.out.println("STACK IS FULL");
}
else
{
a[top]=item;
top++;
}
}
void pop()
{
if(top==0)
{
System.out.println("STACK EMPTY");
}
else
{
top--;
out=a[top];
}
System.out.println(out);
}
void display()
{
if(top==0){
System.out.println("STACK EMPTY");
}
else
{
for(i=top-1;i>=0;i--)
System.out.println(+a[i]);
}
}
}
class Stack
{
public static void main(String[]args)
{
DataInputStream get=new DataInputStream(System.in);
int ch = 0,t = 0;
mystack obj=new mystack();
obj.getdata();
To display stacks
System.out.println("1.PUSH 2.POP 3.DISPLAY");
try {
ch=Integer.parseInt(get.readLine());
} catch (IOException ex) {
Logger.getLogger(Stack.class.getName()).log(Level.SEVERE, null, ex);
}
while(ch!=4)
{
System.out.println("1.PUSH 2.POP 3.DISPLAY");
switch(ch)
{ enter code here
case 1:
try{
t=Integer.parseInt(get.readLine());
}
catch(IOException e)
{
}
System.out.println("value");
try {
t=Integer.parseInt(get.readLine());
obj.push(t);
} catch (IOException ex) {
Logger.getLogger(Stack.class.getName()).log(Level.SEVERE, null, ex);
}
break;
case 2:
obj.pop();
break;
case 3:obj.display();
break;
}
}
}
}
나는 회문을 만드는 방법을 알아낼 수 없습니다 난 출력 할 수 없습니다 내 스택
다행히도이 답변에서 얻은 업 보턴은 곧 당신이 가질 것임을 의미합니다. :). – Joehot200