package com.codegym.task.task04.task0412;
/*
Positive and negative numbers
*/
import java.io.*;
public class Solution {
public static void main(String[] args) throws Exception {
//write your code here
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String snr = reader.readLine();
int nr = Integer.parseInt(snr);
int newnr = 0;
if(nr == 0)
System.out.println("zero");
else if(nr < 0) {
nr++;
System.out.println(nr);
}
else
newnr = nr * 2;
System.out.println(newnr);
}
}
When I try to run it in the online compiler I get the error message "Error converting a string to a number (invalid format)." For some reason IntellJ runs it fine.
It also claims that it does not fulfill requirement with posting "zero" if number is 0, but it does compile and post "zero" when 0 in IntellJ.
What it going on? package com.codegym.task.task04.task0412;
/*
Positive and negative numbers
*/
import java.io.*;
public class Solution {
public static void main(String[] args) throws Exception {
//write your code here
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String snr = reader.readLine();
int nr = Integer.parseInt(snr);
int newnr = 0;
if(nr == 0)
System.out.println("zero");
else if(nr < 0) {
nr++;
System.out.println(nr);
}
else
newnr = nr * 2;
System.out.println(newnr);
}
}