Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,467
There are 1366 users currently browsing (tf).
  Our Partners:
  TalkFreelance     Design and Development     Programming     Other Programming Languages :

Java help

Thread title: Java help
Closed Thread    
    Thread tools Search this thread Display Modes  
10-15-2008, 12:19 PM
Tanax is offline Tanax
Status: I'm new around here
Join date: Nov 2006
Posts: 6
iTrader: 0 / 0%

Tanax is on a distinguished road

  Old  Java help


I'm having some troubles with a java code that I'm scripting.
It's purpose is to let the user write the start hours, minutes and seconds, and the end hours, minutes and seconds.. and then calculate how many hours, minutes and seconds there are from start to end.

I've already got it so they can write in their stuff, and that.
I'm just having troubles with solving the counting part.

Obviously, it's just no to take the end seconds - the start seconds, because what if the start second is less than the end seconds? Then another MINUTE must be withdrawed... soo, how would I solve this?

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(;
		// Start
		System.out.print("Starttid (tt:mm:ss): ");
		start =;
		// Mål
		System.out.print("Målgång (tt:mm:ss): ");
		end =;
		// Rensa
		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");
Sorry for swedish things in it.. but I think you'll understand anyways!
Thanks in advance.

Closed Thread    

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

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed