SOURCE: create program for A-D:
A.) If else statement using Javascript
<script type="text/javascript">
//If the time is less than 10, you will get a "Good morning" greeting.
//Otherwise you will get a "Good day" greeting.
var d = new Date();
var time = d.getHours();
if (time < 10)
{
document.write("Good morning!");
}
else
{
document.write("Good day!");
}
</script>
B.) Switch Case Statement Using C#
using
System;
class SwitchSelect
{
public static void Main()
{
string myInput;
int myInt;
begin:
Console.Write("Please enter a number
between 1 and 10: ");
myInput = Console.ReadLine();
myInt = Int32.Parse(myInput);
// switch with
integer type
switch (myInt)
{
case 1:
Console.WriteLine("Your number is {0}.", myInt);
break;
case 2:
Console.WriteLine("Your number is {0}.", myInt);
break;
case 3:
Console.WriteLine("Your number is {0}.", myInt);
break;
default:
Console.WriteLine("Your number {0} is not
between 1 and 3.", myInt);
break;
}
decide:
Console.Write("Type \"continue\" to go
on or \"quit\" to stop: ");
myInput = Console.ReadLine();
// switch with
string type
switch (myInput)
{
case "continue":
goto begin;
case "quit":
Console.WriteLine("Bye.");
break;
default:
Console.WriteLine("Your input {0} is
incorrect.", myInput);
goto decide;
}
}
}
C. For Loop Statement using C++
for(i=10; i > -1; i--)
{
if(i == 0)
cout << "Blast Off!" << endl;
else
cout << i << endl;
}
}
D. While Loop Using Java
void main() {
int counter = 1;
while(counter < 5 )
{
printLine("counter is equal to " + counter);
counter = counter + 1 ;
}
printLine("Goodbye");
}
67 views
Usually answered in minutes!
×