/******************************************************************************
Online C# Compiler.
Code, Compile, Run and Debug C# program online.
Write your code in this editor and press "Run" button to execute it.
*******************************************************************************/
using System;
class HelloWorld {
public static int Q2(int[] arr, int num) {
int total=0;
for (int i=0; i < arr.Length-1; i++)
{
if (arr[i] > 0 && 7 < arr[i])
{
total+= arr[i];
}
}
return total;
}
public static int CountMonths(int[] arr) {
int count=0;
for (int i=0; i < arr.Length-1; i++)
{
if (arr[i] > 0 && 7 < arr[i])
{
count++;
}
}
return count;
}
public static void Test04()
{
int[] arr = {1,9,3,4,8,11};
int x = CountMonths(arr);
Console.WriteLine("Test04 - x: {0}", x);
}
public static void Test03()
{
Jewel Ring1 = new Jewel(120, true);
//or
Jewel Ring2 = new Jewel(120);
}
public static void Test02()
{
Student b1= new Student(1111,92);
Student b2= new Student(3333,200);
if ( b1.IsInRange())
{
Console.WriteLine("***");
}
else
b1.SetMark(999);
if ( b2.IsInRange())
{
Console.WriteLine("yes");
}
else
b2.SetMark(999);
Console.WriteLine("b1 - " + b1);
Console.WriteLine("b2 - " + b2);
}
public static void Test01()
{
int[] a = {2,8,8,8,12,24,7,7,6};
int[] b= new int[a.Length-1];
int count=0;
for (int i=0; i < a.Length-1; i++)
{
if (a[i]== a[i+1])
{
b[count]=a[i];
count++;
}
}
for (int i=0; i < b.Length; i++)
{
Console.Write( b[i]+",");
}
Console.WriteLine();
}
static void Main() {
Console.WriteLine("Hello World");
//Test01();
//Test02();
//Test02();
Test04();
}
}
using System;
public class Student
{
private int num;
private int mark;
public Student(int num, int mark)
{
this.num = num;
this.mark = mark;
}
public bool IsInRange()
{
return (this.mark > -1 && this.mark < 101);
}
public void SetMark(int mark)
{
this.mark=mark;
}
public override string ToString()
{
return "num:"+ this.num +", mark:" + this.mark;
}
}
using System;
public class Jewel
{
private int price;
private bool isGold;
public Jewel(int price, bool isGold)
{
this.price = price;
this.isGold = isGold;
}
public Jewel(int price)
{
this.price = price;
this.isGold = true;//false
}
public int GetPrice()
{
return this.price;
}
public void SetPrice(int price)
{
this.price=price;
}
public override string ToString()
{
return "price:"+ this.price +", isGold:" + this.isGold;
}
}