PDA

Click to See Complete Forum and Search --> : Help with this...


Ervilha
Jun 9th, 2008, 09:28 AM
I want to do this...

Enter the day of birth: 10
Enter the month of birth: 2
Enter the year of birth: 1986

You were born in: February

I only now how to do this in vb, this is the code that i used...



'// Declaração de Variáveis
Dim dia, ano, i As Integer
Dim meses(12), resposta As String

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'// Inicialização de Variáveis
meses(1) = "Janeiro"
meses(2) = "Fevereiro"
meses(3) = "Março"
meses(4) = "Abril"
meses(5) = "Maio"
meses(6) = "Junho"
meses(7) = "Julho"
meses(8) = "Agosto"
meses(9) = "Setembro"
meses(10) = "Outubro"
meses(11) = "Novembro"
meses(12) = "Dezembro"

Do
'// Entrada de Dados
dia = InputBox("Entre com o dia do nascimento do aluno:")
meses(i) = InputBox("Entre com o mês do nascimento do aluno:")
ano = InputBox("Entre com o ano do nascimento do aluno:")

'// Processamento de Dados
For i = meses(i) To meses(i)

'// Saida de Dados
MsgBox("O estudante nasceu em " & dia & " de " & meses(i) & " de " & ano)
Next

'// Perguntar se Quer Continuar
resposta = InputBox("Deseja Continuar S/N?:")
resposta = resposta.ToUpper
Loop Until (resposta.Equals("N"))
Close()
End Sub
End Class

eranga262154
Jun 24th, 2008, 05:33 AM
Are you want to do it in Java? If not this question is not related to Java, and moderators should move this to the proper sub-forum.

ComputerJy
Jun 24th, 2008, 02:54 PM
This is how you can do it
import java.util.Scanner;

public class Main
{
public static void main(String[] args) throws Exception
{
String[] months =
{
"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
};
Scanner s = new Scanner(System.in);
do
{
System.out.println("Enter the month of birth: ");
int month = s.nextInt();
if (month <= 12 && month > 0)
System.out.println("You were born in: " + months[month - 1]);
System.out.println("Do you want to continue? (Y/N)");
} while (((char) System.in.read()) == 'Y');
}

private Main()
{
}
}