.
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) [Link] (“Enter the first Integer”);
4) x= Convert.ToInt32([Link]());
5) [Link] (“Enter the Second Integer”);
6) y= Convert.ToInt32 ([Link]());
7) [Link] (“Enter the third Integer);
8) z= Convert.ToInt32 ([Link]());
9) result =x*y*z;
10) [Link] (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.,
[Link](“ Please enter your name.”);
name= [Link]();
[Link](“Please enter the first number.”);
numA= Convert.ToInt32 ([Link]()); //store the first number
[Link](“Please enter the second number.”);
numB= Convert. ToInt32 ([Link]()); //store the second number
[Link](“Please enter the third number.”);
numC=Convert. ToInt32 (Console. ReadLine()):
sum=numA+numb+numC;
[Link](“Hello,{0}”,name);
[Link](“the total is={0}”,sum);
[Link](“Press enter to exit”);
[Link]();
}
}// End of Add
.NET PROGRAMMING
QUARTER 1, WEEK 3
WORKSHEET NO. 1
C# Basic Syntax
Activity 1
My First C#Program
using System;
using [Link];
using [Link];
using [Link];
namespace First_c_sharp_code
class Program
static void Main(string[] args)
string name; //Variable for storing string value
//Displaying message for entring value
[Link]("Milben Cera");
//Accepting and holding values in name variable
name = [Link]();
//Displaying Output
[Link]("Welcome {0} in your first csharp program", name);
//Holding console screen
[Link]();
}
}
.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 [Link];
classFC
{
public static Void main (String args [] )
{
double f,c;
Scanner sc = new Scanner ([Link]);
[Link](“Choose type of conversion \ n 1. Fahrenheit to celcius \ n
int ch=sc. next Int ();
Switch (ch)
{
case 1: [Link](“Enter Fahrenheit temperature”);
f=sc. next Double ();
c= (f-32)*5/9;
[Link] (Celsius temperature is = “+c);
break;
case 2:[Link] (“Enter Celsius temperature”);
c=sc. next Double ();
f=(19*c)/5)+32;
[Link] (“Fahrenheit temperature is =”+f);
break;
default: [Link] (“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;
[Link]("\n\n");
[Link]("Read 10 numbers and calculate sum and average:\n");
[Link]("----------------------------------------------");
[Link]("\n\n");
[Link]("Input the 10 numbers : \n");
for (i=1;i<=10;i++)
[Link]("Number-{0} :",i);
n= Convert.ToInt32([Link]());
sum +=n;
avg=sum/10.0;
[Link]("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--){
[Link]("*");
[Link]("\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--){
[Link](" ");
for(int z=1; z<=x; z++){
[Link](" *");
[Link]("\n\n");
output: