Scanner reader = new Scanner(System.in);
System.out.println("ram available: ");
int ram = 0;
try
{
ram = Integer.parseInt(reader.next());
}
catch(Exception e)
{
...
Type: Posts; User: helloworld922
Scanner reader = new Scanner(System.in);
System.out.println("ram available: ");
int ram = 0;
try
{
ram = Integer.parseInt(reader.next());
}
catch(Exception e)
{
...
Two solutions:
If you are using Integer.parseInt(string), then it will automatically detect this problem and throw an exception. All you have to do is catch it and display the message.
try
{
...