Got this code:
System.out.println("Introduce salary: ");
Scanner alpha8 = new Scanner(System.in);
String salary = alpha8.nextLine();
int salaryNew = 0;
if(salary .isEmpty()){
salary = null;
}else{
salaryNew = Integer.parseInt(salary);
}
How can i make this to output only 1 variable from the IF? Because if the introduced value is null (blank space from scanner, like enter) sets salary to null wich i use later on.
The thing is that i either need a "null" or an "int value".
In the "else" i cannot do this:
salary = Integer.parseInt(salary);
because id get an error, neither i can parse int into to null.
And this methodto convert dates:
public static Date changeDate(String introducedDate) throws ParseException {
SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd");
java.util.Date sqlDate = sdf.parse(introducedDate);
java.sql.Date newSqlDate= new java.sql.Date(sqlDate.getTime());
return newSqlDate;
}
If introducedDate is null it will throw an exception, how can i change that method to return NULL if introduced date is NULL too?
ifstatement?