Galera eu digito minha STRING 'primeiroDia' dessa maneira "Dia 5". Eu quero pegar tudo que vem depois do ESPAÇO, como faço isso?
import java.util.Scanner;
import java.util.Locale;
public class Main{
public static void main(String[] args){
Locale.setDefault(Locale.US);
Scanner entradaTeclado = new Scanner(System.in);
String primeiroDia = entradaTeclado.nextLine();
String horaDia1 = entradaTeclado.nextLine();
int diaInicio = Integer.parseInt(primeiroDia);
char h1 = horaDia1.charAt(0);
char h12 = horaDia1.charAt(1);
String pegaHora = Character.toString(h1) + Character.toString(h12);
int horaInicial = Integer.parseInt(pegaHora);
char m1 = horaDia1.charAt(5);
char m12 = horaDia1.charAt(6);
String pegaMinuto = Character.toString(m1) + Character.toString(m12);
int minutoInicial = Integer.parseInt(pegaMinuto);
char s1 = horaDia1.charAt(10);
char s12 = horaDia1.charAt(11);
String pegaSegundo = Character.toString(s1) + Character.toString(s12);
int segundoInicial = Integer.parseInt(pegaSegundo);
String segundoDia = entradaTeclado.nextLine();
String horaDia2 = entradaTeclado.nextLine();
int diaFinal = Integer.parseInt(segundoDia);
h1 = horaDia2.charAt(0);
h12 = horaDia2.charAt(1);
pegaHora = Character.toString(h1) + Character.toString(h12);
int horaFinal = Integer.parseInt(pegaHora);
m1 = horaDia2.charAt(5);
m12 = horaDia2.charAt(6);
pegaMinuto = Character.toString(m1) + Character.toString(m12);
int minutoFinal = Integer.parseInt(pegaMinuto);
s1 = horaDia2.charAt(10);
s12 = horaDia2.charAt(11);
pegaSegundo = Character.toString(s1) + Character.toString(s12);
int segundoFinal = Integer.parseInt(pegaSegundo);
int resultDia = 0;
int resultHora = 0;
int resultMinuto = 0;
int resultSegundo = 0;
if(diaInicio == diaFinal){
if(segundoFinal < segundoInicial){
minutoFinal--;
segundoFinal += 60;
if(minutoFinal < minutoInicial){
horaFinal--;
minutoFinal += 60;
}
resultHora = horaFinal - horaInicial;
resultMinuto = minutoFinal - minutoInicial;
resultSegundo = segundoFinal - segundoInicial;
}else{
if(minutoFinal < minutoInicial){
horaFinal--;
minutoFinal += 60;
}
resultHora = horaFinal - horaInicial;
resultMinuto = minutoFinal - minutoInicial;
resultSegundo = segundoFinal - segundoInicial;
}
}else{
if(horaInicial > horaFinal){
diaFinal--;
resultDia = diaFinal - diaInicio;
resultHora = (24 + horaFinal - horaInicial);
resultMinuto = Math.abs(minutoInicial - minutoFinal);
resultSegundo = Math.abs(segundoInicial - segundoFinal);
}else{
resultDia = diaFinal - diaInicio;
resultHora = Math.abs(horaInicial - horaFinal);
resultMinuto = Math.abs(minutoInicial - minutoFinal);
resultSegundo = Math.abs(segundoInicial - segundoFinal);
}
}
System.out.printf("%d dia(s)\n", resultDia);
System.out.printf("%d hora(s)\n", resultHora);
System.out.printf("%d minuto(s)\n", resultMinuto);
System.out.printf("%d segundo(s)\n", resultSegundo);
}
}
o exercicios que eu estou resolvendo e este aki: http://www.urionlinejudge.com.br/judge/problems/view/1061
a unica coisa que falta msm e como vou usar um delimitador para pegar somento o que vem apos o espaço na minha String primeiroDia.
obrigado desde ja.