Vous êtes sur la page 1sur 3

using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace tugas2
{
class Program
{
static void Main(string[] args)
{
// deklarasi
int pilih;

Console.WriteLine("Menu");
Console.WriteLine("1.Kata Terbalik");
Console.WriteLine("2.Contoh Perhitungan");
Console.WriteLine("3.Buat Pola");
Console.WriteLine("4.Keluar");
Console.WriteLine("=====================================");

Console.Write("pilih (1-4): ");


pilih = Convert.ToInt16(Console.ReadLine());
switch(pilih)
{

case 1:
string str = "", reverse = "";
int Length = 0;
Console.Write("Masukan kata: ");
//Getting String(word) from Console
str = Console.ReadLine();
//Calculate length of string str
Length = str.Length - 1;
while(Length>=0)
{
reverse = reverse + str[Length];
Length--;
}
//Displaying the reverse word
Console.WriteLine("Kata terbalik: {0}",reverse);
Console.ReadLine();
break ;

case 2:
{
Console.WriteLine(" Contoh Perkalian: ");
for (int m = 1; m <= 10; m++)
Console.Write("{0} ", m);
Console.WriteLine();

for (int m = 1; m <= 10; m++)


Console.Write("{0} ", m * 2);
Console.WriteLine();

for (int m = 1; m <= 10; m++)


Console.Write("{0} ", m * 3);
Console.WriteLine();

for (int m = 1; m <= 10; m++)


Console.Write("{0} ", m * 4);
Console.WriteLine();

for (int m = 1; m <= 10; m++)


Console.Write("{0} ", m * 5);
Console.WriteLine();

for (int m = 1; m <= 10; m++)


Console.Write("{0} ", m * 6);
Console.WriteLine();

for (int m = 1; m <= 10; m++)


Console.Write("{0} ", m * 7);
Console.WriteLine();

for (int m = 1; m <= 10; m++)


Console.Write("{0} ", m * 8);
Console.WriteLine();

for (int m = 1; m <= 10; m++)


Console.Write("{0} ", m * 9);
Console.WriteLine();

for (int m = 1; m <= 10; m++)


Console.Write("{0} ", m * 10);
Console.ReadKey();
}
break;

case 3:
bool flag = true;
Console.Write("Masukkan bilangan: ");
int n = Convert.ToInt32(Console.ReadLine());

//Print 10 lines.
for (int i = 0; i < 10; i++)
{
if (i % 2 == 0)//odd
{
if (flag)
{
Console.WriteLine(string.Format("{0," + n + "}", "*"));
}
else
{
Console.WriteLine(string.Format("{0,-" + n + "}", "*"));
}
flag = !flag;
}
else//even
{
for (int j = 0; j < n; j++)
{
Console.Write("*");
}
Console.WriteLine();
}
}
Console.ReadKey();
break;

case 4:
Console.WriteLine("Keluar aplikasi..");
Console.ReadKey();
break;

default:
Console.WriteLine("Inputan salah");
Console.ReadKey();
//main();
break;
}
}
}
}

Vous aimerez peut-être aussi