Hi...I did some book exercices..i want to ask you are these code right or not?
Question1---Write a programme to display a random choices from a set of 3 choices for breakfast....
i wrote this code...
public class Exercice3_1
{
public static void main(String[] args)
{
String breakFast = null;
int choice=0;
choice = (int)(3*Math.random());
switch(choice)
{
case 1:
breakFast = "Scrambled";
System.out.println(breakFast);
break;
case 2:
breakFast = "Sandwitch";
System.out.println(breakFast);
break;
case 3:
breakFast = "Eggs";
System.out.println(breakFast);
break;
}
}
}
Question-2
A lottery requires that you select six different numbers from the integer 1 tp 49..and generate five sets of entries...
i wrote this code
public class Exercice3_3
{
public static void main(String[] args)
{
for(int i=0; i<5; i++)
{
int number = (int)(49*Math.random());
System.out.println(number);
}
}
}
Question-3
Write a programme to generate a random sequence of Capital letters that does not include vowels..
i wrote this code
public class Exercice3_4
{
public static void main(String[] args)
{
for(int i=65; i<=90; i++)
{
char symbol = (char)(i);
if(!(symbol=='A' || symbol =='E' || symbol=='I' || symbol=='O' || symbol=='U'))
{
System.out.println(symbol);
}
}
}
}
Kindly tell me all these code are right or not?
Regards...
Farhad