he operator / is undefined for the argument type(s) String, int
Code :
import java.io.*;
public class FormatTime
{
public static void main(String[] args)
{
//this will fetch our input values
BufferedReader usrInput = new BufferedReader( new InputStreamReader( System.in) );
System.out.println("Enter a number in seconds to format: ");
String secs = usrInput.readLine();
int hours = (secs / 3600);
int remainder = (secs % 3600);
int minutes = (remainder / 60);
int seconds = (remainder % 60);
String Hour = (hours < 10 ? "0" : "") + hours;
String Min = (minutes < 10 ? "0" : "") + minutes;
String Sec = (seconds < 10 ? "0" : "") + seconds ;
System.out.println(Hour +":"+ Min+":"+Sec);
}
}
Could someone help me out with this error. I have googled but I just dont get it. I am new, very new. Started a online class 3 weeks ago and I have my first program due. My book just showed up today and I am way behind. this is the error I am getting.
Code :
"The operator / is undefined for the argument type(s) String, int"
Re: he operator / is undefined for the argument type(s) String, int
The problem is here:
String secs = usrInput.readLine();
int hours = (secs / 3600);
int remainder = (secs % 3600);
You are trying to divide secs by 3600, but secs is a String and 3600 is an int.
So you are trying to do: String / int, that's why you're receiving that error.
To fix this, make secs and Integer like this:
String secString = usrInput.readLine();
int secs = Integer.parseInt(secString);
or achieve the same result by this:
int secs = Integer.parseInt(userInput.readLine());
Both statements will do the same.
Re: he operator / is undefined for the argument type(s) String, int
or this:
Code :
int secs = new Scanner(System.in).nextInt();
int hours = secs/3600;
//...