So I have this method that returns the time when a tv-show ends(e.g.: 21:15),but when the hour or minute is under 10 I need the method to return something like this : 21:05.
I tried like this, but because msg1 and msg2 are type String they can’t return my int, if the elses occur.
What can I do?
Helpfull Info: Im in my first year of Computer Engineering.
public static final int ZERO = 0;
public String endsWhen(){
String msg1="";
String msg2="";
if(fhour<10)
msg1=ZERO + getFHour();
else
msg1=getFHour(); //error here
if(fmin<10)
msg2=ZERO+getFMin;
else
msg2=getFMin; //error here
return msg1 + ":" + msg2;
}
You cannot assign an int primitive to a string. assuming your getFHour() and getFMin() returns int.
try:
OR, you can also convert an int to a string with Integer.toString() method.
However you should be using SimpledateFormater to format Dates and Time