Latest Articles
 by awuehr on 11-10-2008 in Tips & Tricks by Village Idiot on 11-04-2008 in Classes & Objects by codefreek on 10-23-2008 in Basic by wiifanatic on 09-12-2008 in Security & Permissions by drewbee on 07-03-2008 in Tips & Tricks
 IRC Channel
 Join the friendly bunch on IRC... (#TalkPHP on Freenode) ...Also available via a web interface. See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
 Associates
 Associates
 TalkPHP » Calculate
 10-15-2008, 01:08 PM #1 (permalink) The Prestige        Join Date: Sep 2007 Location: Sweden, Stockholm Posts: 1,080 Thanks: 115 Calculate I have a script, actually in Java, but nevermind that. And it's supposed to let the user print in starttime in hours, minutes and seconds. And then the endtime in hours, minutes and seconds. Then it calculates how many hours, minutes, and seconds it took. Obviously it's a bit trickier than just endseconds - startseconds etc, since the startseconds could be more than the endseconds, which would result in that it took 1 more minute. I think I recall that I had to use "%" but not sure how. Please help. If it's to any help, here's the javacode if someone knows java, but it's really just the math calculation I need help with. java Code: `import java.util.*;public class Calculate{    public static void main(String[] args)    {                // Deklarera variabler        String start, end, nextStart, nextEnd;        int start_hours, start_minutes, start_seconds, end_hours, end_minutes, end_seconds, result_hours, result_minutes, result_seconds;                // Initialisera den importerade klassen        Scanner keyboard = new Scanner(System.in);                // Start        System.out.print("Starttid (tt:mm:ss): ");        start = keyboard.next();                // Mål        System.out.print("Målgång (tt:mm:ss): ");        end = keyboard.next();                // Rensa        keyboard.nextLine();                StringTokenizer startTime = new StringTokenizer(start, ":");        StringTokenizer endTime = new StringTokenizer(end, ":");                nextStart = startTime.nextToken();        start_hours = Integer.parseInt(nextStart);        nextStart = startTime.nextToken();        start_minutes = Integer.parseInt(nextStart);        nextStart = startTime.nextToken();        start_seconds = Integer.parseInt(nextStart);                nextEnd = endTime.nextToken();        end_hours = Integer.parseInt(nextEnd);        nextEnd = endTime.nextToken();        end_minutes = Integer.parseInt(nextEnd);        nextEnd = endTime.nextToken();        end_seconds = Integer.parseInt(nextEnd);                System.out.println("\nStarttid:\nTimme: " + start_hours + "\nMinut: " + start_minutes + "\nSekund: " + start_seconds);        System.out.println("\nMålgångstid:\nTimme: " + end_hours + "\nMinut: " + end_minutes + "\nSekund: " + end_seconds);        System.out.println("\nResultat: Blaa");            }}` __________________

 Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)