You are on page 1of 8

.

NET PROGRAMMING
QUARTER 1, WEEK 3
WORKSHEET NO. 2
C# Basic Syntax

Activity 1
(Answers)
1) Access modifier

2) int x,y,z result or int x;


int y;
int z;
int result;

3) Console.WriteLine (“Enter the first Integer”);

4) x= Convert.ToInt32(Console.ReadLine());

5) Console.WriteLine (“Enter the Second Integer”);

6) y= Convert.ToInt32 (Console.Readline());

7) Console.WriteLine (“Enter the third Integer);

8) z= Convert.ToInt32 (Console.ReadLine());

9) result =x*y*z;

10) Console.Writeline (the product is: {0}”,result);


PERFORMANCE TASK

Using System
public class Add
{//Begin
static void main(String[] args)
{
string name;
//Variable
Int numA //1st number
Int numB//2nd number
Int numC//3rd number
Int sum // result.,

Console.WriteLine(“ Please enter your name.”);


name= Console.ReadLine();
Console.WriteLine(“Please enter the first number.”);
numA= Convert.ToInt32 (Console.Readline()); //store the first number
Console.WriteLine(“Please enter the second number.”);
numB= Convert. ToInt32 (Console.Readline()); //store the second number
Consule.WriteLine(“Please enter the third number.”);
numC=Convert. ToInt32 (Console. ReadLine()):
sum=numA+numb+numC;

Console.WriteLine(“Hello,{0}”,name);
Console.WriteLine(“the total is={0}”,sum);

Console.WriteLine(“Press enter to exit”);


Console.Readkey();
}
}// End of Add
.NET PROGRAMMING
QUARTER 1, WEEK 3
WORKSHEET NO. 1
C# Basic Syntax

Activity 1
My First C#Program

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace First_c_sharp_code

class Program

static void Main(string[] args)

string name; //Variable for storing string value

//Displaying message for entring value

Console.WriteLine("Milben Cera");

//Accepting and holding values in name variable

name = Console.ReadLine();

//Displaying Output

Console.WriteLine("Welcome {0} in your first csharp program", name);

//Holding console screen

Console.ReadLine();

}
}
.NET PROGRAMMING
QUARTER 1, WEEK 3
C# Basic Syntax

Activity 1
1)True 6)False
2)True 7)False
3)False 8)True
4)True 9)True
5)True 10)True
QUARTER 1, WEEK 3-4
WORKSHEET # 1
JAVA PROGRAMMING

PERFORMANCE 7

import java.util.Scanner;
classFC
{

public static Void main (String args [] )


{
double f,c;
Scanner sc = new Scanner (system.in);
System.out.println(“Choose type of conversion \ n 1. Fahrenheit to celcius \ n
int ch=sc. next Int ();
Switch (ch)
{
case 1: System.out.println(“Enter Fahrenheit temperature”);
f=sc. next Double ();
c= (f-32)*5/9;
System.out.println (Celsius temperature is = “+c);
break;
case 2:System.out.println (“Enter Celsius temperature”);
c=sc. next Double ();
f=(19*c)/5)+32;
System.out.println (“Fahrenheit temperature is =”+f);
break;
default: System.out.println (“please choose valid choice”);
}
}
}
MILBEN P. CERA
ICT-2 PROGRAMMING

Programming .NET Technology


Test your programming ability.

(ANSWERS)
1) Create a console program that will display the average of ten digits from the user. (50 points)
using System;

public class Exercise4

public static void Main()

int i,n,sum=0;

double avg;

Console.Write("\n\n");

Console.Write("Read 10 numbers and calculate sum and average:\n");

Console.Write("----------------------------------------------");

Console.Write("\n\n");

Console.Write("Input the 10 numbers : \n");

for (i=1;i<=10;i++)

Console.Write("Number-{0} :",i);

n= Convert.ToInt32(Console.ReadLine());

sum +=n;

avg=sum/10.0;

Console.Write("The sum of 10 no is : {0}\nThe Average is : {1}\n",sum,avg);

}
2) create a console program that will display the following stars formation below.

A) 50 points
input:

using System;

class Pyramid

static void Main() {

for(int x=1; x<=5; x++){

for(int y=5; y>=x; y--){

Console.Write("*");

Console.Write("\n\n");

output:

B) 50 points
input:

using System;

class Pyramid

static void Main() {

for(int x=1; x<=5; x++){

for(int y=5; y>=x; y--){


Console.Write(" ");

for(int z=1; z<=x; z++){

Console.Write(" *");

Console.Write("\n\n");

output:

You might also like