I'm using FindBugs and this error keeps generating:
Reliance on default encoding:
Found a call to a method which will perform a byte to String (or String to byte) conversion, and will assume that the default platform encoding is suitable. This will cause the application behavior to vary between platforms. Use an alternative API and specify a charset name or Charset object explicitly.
I think it has something to do with the Scanner here is my code:
package mystack;
import java.util.*;
public class MyStack {
private int maxSize;
private int[] stackArray;
private int top;
public MyStack(int s) {
maxSize = s;
stackArray = new int[maxSize];
top = -1;
}
public void push(int j) {
stackArray[++top] = j;
}
public int pop() {
return stackArray[top--];
}
public int peek() {
return stackArray[top];
}
public int min() {
return stackArray[0];
}
public boolean isEmpty() {
return (top == -1);
}
public boolean isFull() {
return (top == maxSize - 1);
}
public static void main(String[] args) {
Scanner read = new Scanner(System.in);
char end;
System.out.println("Please enter the size of the Stack: ");
int size=read.nextInt();
MyStack stack = new MyStack(size);
do{
if(stack.isEmpty()){
System.out.println("Please fill the Stack: (PUSH) \nBecause Stack is Empty.");
int add;
for(int i=0; i<size; i++)
{add=read.nextInt();
stack.push(add);}
}//End of if
else if(stack.isFull()){
System.out.println("Do you want to 1)POP 2)Know the Peek 3)Know the Min");
int option=read.nextInt();
if(option==1)
stack.pop();
else if (option==2)
System.out.println("The Peek= "+stack.peek());
else if (option==3)
System.out.println("The Min= "+stack.min());
else System.out.println("Error, Choose 1 or 2 or 3");
}//End of if
else
{ System.out.println("Do you want to 1)POP 2)Know the Peek 3)Know the Min 4)PUSH");
int option=read.nextInt();
if(option==1)
stack.pop();
else if (option==2)
System.out.println("The Peek= "+stack.peek());
else if (option==3)
System.out.println("The Min= "+stack.min());
else if(option==4)
{int add=read.nextInt();
stack.push(add);}
}//end else
System.out.print("Stack= ");
for(int i=0; i<=stack.top; i++)
{ System.out.print(stack.stackArray[i]+" ");}
System.out.println();
System.out.println();
System.out.println("Repeat? (e=exit)");
end=read.next().charAt(0);
System.out.println();
}while(end!='e');
System.out.println("End Of Program");
}//end main
}//end MyStack
It is a stack obviously, works fine.