-
邏輯非 !? 取反,如果結(jié)果真 返回假,如果結(jié)果假 返回真
邏輯與 && 兩布爾表達(dá)式結(jié)果同時為True時結(jié)果為True,判斷兩個布爾類型表達(dá)式有一個為False,結(jié)果就為False
邏輯或 || 只要兩個表達(dá)式有一個位True,結(jié)果就為True,兩個表達(dá)式同時為False時返回結(jié)果才為False
查看全部 -
()不會打印3
A Console.Write((int)3.6);浮點(diǎn)型強(qiáng)制轉(zhuǎn)換整形去掉小數(shù)點(diǎn) 結(jié)果3
B Console.Write((double)3.6); 浮點(diǎn)型3.6
C Console.Write((int)3); 整形3
D Console.Write((double)3); 輸出浮點(diǎn)型3
查看全部 -
試了試
目前還不會在同一個文件里,創(chuàng)建新的類
不然,就可以
創(chuàng)建 學(xué)生類 class student
包含 (屬性) 姓名和分?jǐn)?shù)? string name;int score;
同時包含 (方法) set姓名和set分?jǐn)?shù) 以及 get姓名和get分?jǐn)?shù)
?????? ?void????setName()
????????void????setScore()
????????string? ? getName()
????????int? ? getName()
創(chuàng)建包含8個學(xué)生的 學(xué)生數(shù)組????student[] ss=new student[8];
給每個學(xué)生 錄入 姓名和分?jǐn)?shù)
????????ss[0].setName("吳松");
????????ss[0].setScore(89);
然后 比較學(xué)生的分?jǐn)?shù)得到最大值和序列號
根據(jù)序列號可以get姓名
記錄,如果以后還記得 嘗試一下
查看全部 -
using?System; using?System.Collections.Generic; using?System.Text; namespace?projAboveAvg { ????class?Program ????{ ????????static?void?Main(string[]?args) ????????{ ????????????string[]?names?=?new?string[]?{"景珍","林慧洋","成蓉","洪南昌","龍玉民","單江開","田武山","王三明"}; ????????????int[]?score?=?new?int[]?{90,65,88,70,46,81,100,68}; ????????????int?sum?=?0,avg; ????????????foreach(int?i?in?score){ ????????????????sum?+=?i; ????????????} ????????????avg?=?sum?/?score.Length; ????????????Console.Write("平均分是"+?avg?+",高于平均分的有:"); ????????????for(int?i?=?0;i<score.Length;i++){ ????????????????if(score[i]?>?avg){ ????????????????????Console.Write(names[i]+"?"); ????????????????} ????????????} ????????} ????} }
查看全部 -
using?System; using?System.Collections.Generic; using?System.Text; namespace?projGetMaxScore { ????class?Program ????{ ????????static?void?Main(string[]?args) ????????{ ????????????string[,]?stu?=?new?string[8,?2]?{?{?"吳松",?"89"},?{?"錢東宇","90"},?{"伏晨","98"?},?{"陳陸","56"?},?{"周蓉","60"?},?{"林日鵬","91"?},{"何昆","93"?},?{"關(guān)欣","85"?}?}?; ??????????//?查找分?jǐn)?shù)最高的同學(xué) ????????????int?maxScore?=?int.MinValue; ????????????string?topStudent?=?""; ????????????//?獲取數(shù)組的行數(shù)和列數(shù) ????????????int?rows?=?stu.GetLength(0); ????????????int?cols?=?stu.GetLength(1); ????????????//?遍歷數(shù)組 ????????????for(int?i?=?0;i<rows;i++){ ????????????????int?score?=?int.Parse(stu[i,1]); ????????????????if(score?>?maxScore){ ????????????????????maxScore?=?score; ????????????????????topStudent?=?stu[i,0]; ????????????????} ????????????} ????????????//?輸出分?jǐn)?shù)最高的同學(xué)的姓名和分?jǐn)?shù) ????????????Console.WriteLine($"分?jǐn)?shù)最高的同學(xué)是{topStudent},分?jǐn)?shù)是{maxScore}"); ????} ????} }
查看全部 -
在 C# 中,GetLength 和 Length 是數(shù)組的兩個不同的屬性,用于獲取數(shù)組的長度信息。它們之間的主要區(qū)別在于:
Length 屬性:
示例:
csharpCopy codeint[] arr = new int[] { 1, 2, 3, 4, 5 };int length = arr.Length; // length 的值是 5
Length 是數(shù)組的屬性,用于獲取數(shù)組的總元素個數(shù)。
對于一維數(shù)組,Length 返回的是數(shù)組的總元素個數(shù)。
對于多維數(shù)組,Length 返回的是數(shù)組的總元素個數(shù),包括所有維度的元素個數(shù)的乘積。
Length 是一個整數(shù)屬性。
GetLength 方法:
示例:
csharpCopy codeint[,] matrix = new int[,] { { 1, 2 }, { 3, 4 }, { 5, 6 } };int rows = matrix.GetLength(0); ? ?// rows 的值是 3int columns = matrix.GetLength(1); // columns 的值是 2
GetLength 是一個方法,用于獲取指定維度上的元素個數(shù)。
GetLength 接受一個參數(shù),表示維度的索引。
對于一維數(shù)組,可以使用 GetLength(0) 來獲取數(shù)組的長度。
對于多維數(shù)組,可以使用 GetLength(index) 來獲取指定維度的元素個數(shù)。
總的來說,Length 用于獲取整個數(shù)組的元素個數(shù),而 GetLength 用于獲取指定維度上的元素個數(shù)。
查看全部 -
using?System; using?System.Collections.Generic; using?System.Text; namespace?Test { ????class?Program ????{ ????????static?void?Main(string[]?args) ????????{ ????????????//聲明整型數(shù)組,保存一組整數(shù) ????????????int[]?num?=?new?int[]?{?3,34,43,2,11,19,30,55,20}; ????????????//請完善代碼,判斷數(shù)組中有沒有7的整倍數(shù) ????????????bool?has7?=?false; ????????????foreach(int?x?in?num){ ????????????????if(x%7==0){ ????????????????????has7?=?true; ????????????????????break; ????????????????} ????????????} ????????????if(has7){ ????????????????????Console.Write("有7的整倍數(shù)"); ????????????????} ????????????????else{ ????????????????????Console.Write("沒有7的整倍數(shù)"); ????????????????} ????????} ????} }
查看全部 -
using?System; using?System.Collections.Generic; using?System.Text; namespace?Test { ????class?Program ????{ ????????static?void?Main(string[]?args) ????????{ ????????????string[]?t?=new??string[]{"C","Sh","a","rp"}; ????????????//遍歷字符串?dāng)?shù)組t ????????????foreach(string?x?in?t) ????????????{ ????????????????Console.Write(x); ????????????} ????????} ????} }
查看全部 -
using?System; using?System.Collections.Generic; using?System.Text; namespace?Test { ????class?Program ????{ ????????static?void?Main(string[]?args) ????????{ ????????????//聲明整型數(shù)組,保存一組整數(shù) ????????????int[]?num?=?new?int[]?{?3,34,42,2,11,19,30,55,20}; ????????????//請完善代碼,循環(huán)打印數(shù)組中的偶數(shù) ????????????for(int?i?=?0;i<num.Length;i++){ ????????????????if(num[i]%2==0) ????????????????{ ????????????????????Console.Write(num[i]+","); ????????????????} ????????????} ????????} ????} }
查看全部 -
using?System; using?System.Collections.Generic; using?System.Text; namespace?Test { ????class?Program ????{ ????????static?void?Main(string[]?args) ????????{ ???????????string[]?names?=?{"關(guān)羽","張飛","趙云","馬超","黃忠"};//請?jiān)谶@里完善代碼 ???????????for(int?x=0;x<?names.Length;x++){ ???????????????Console.Write(names[x]+","); ???????????} ????????} ????} }
查看全部 -
using System;
using System.Collections.Generic;
using System.Text;
namespace Test
{
? ? class Program
? ? {
? ? ? ? static void Main(string[] args)
? ? ? ? {
? ? ? ? ? ?string[] names = {"關(guān)羽","張飛","趙云","馬超","黃忠"};//請?jiān)谶@里完善代碼
? ? ? ? ? ?for(int x=0;x< names.Length;x++){
? ? ? ? ? ? ? ?Console.Write(names[x]+",");
? ? ? ? ? ?}
? ? ? ? }
? ? }
}
查看全部 -
using?System; using?System.Collections.Generic; using?System.Text; namespace?Test { ????class?Program ????{ ????????static?void?Main(string[]?args) ????????{ ????????????//聲明“職位”數(shù)組,初始化為:"經(jīng)理","項(xiàng)目主管","技術(shù)總監(jiān)","財(cái)務(wù)主管" ????????????string[]?job?=?new?string[4]{"經(jīng)理","項(xiàng)目主管","技術(shù)總監(jiān)","財(cái)務(wù)主管"}; ????????????for?(int?i?=?0;?i?<?job.Length?;?i++) ????????????{ ????????????????Console.WriteLine(job[i]);//打印職位 ????????????} ????????} ????} }
查看全部 -
using?System; using?System.Collections.Generic; using?System.Text; namespace?Test { ????class?Program ????{ ????????static?void?Main(string[]?args) ????????{ ????????????int[]?age?=?new?int[4];????????;//聲明并初始化長度為4的整形數(shù)組 ????????????//為數(shù)組元素賦值 ????????????age[?0]?=?18; ????????????age[1?]?=?20; ????????????age[?2]?=?23; ????????????age[?3]?=?17; ????????????Console.WriteLine("四名同學(xué)的年齡是:{0}、{1}、{2}、{3}", ????????????????age[?0],age[?1],age[?2],age[?3]); ????????} ????} }
查看全部 -
using?System; using?System.Collections.Generic; using?System.Text; namespace?Test { ????class?Program ????{ ????????static?void?Main(string[]?args) ????????{ ????????????int[]?age?=?new?int[4];????????;//聲明并初始化長度為4的整形數(shù)組 ????????????//為數(shù)組元素賦值 ????????????age[?0]?=?18; ????????????age[1?]?=?20; ????????????age[?2]?=?23; ????????????age[?3]?=?17; ????????????Console.WriteLine("四名同學(xué)的年齡是:{0}、{1}、{2}、{3}", ????????????????age[?0],age[?1],age[?2],age[?3]); ????????} ????} }
查看全部 -
using System;
using System.Collections.Generic;
using System.Text;
namespace Test
{
? ? class Program
? ? {
? ? ? ? static void Main(string[] args)
? ? ? ? {
? ? ? ? ? ? //請完善代碼
? ? ? ? ? ? for(int y=1;y<=7;y++){
? ? ? ? ? ? ? ? for(int x=1;x<=7;x++){
? ? ? ? ? ? ? ? ? ? if(x==y||x+y==8)
? ? ? ? ? ? ? ? ? ? Console.Write("O");
? ? ? ? ? ? ? ? ? ? else{
? ? ? ? ? ? ? ? ? ? ? ? Console.Write(".");
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? Console.WriteLine();
? ? ? ? ? ? }
? ? ? ? }
? ? }
}
查看全部
舉報(bào)