Results 1 to 12 of 12
Thread: Java C#
Hybrid View
-
17th March 2009 22:33 #1
Java C#
, . Java , , C#.
E :
- :Code:import java.util.*; import java.util.List; import java.util.ArrayList; public class list1 { public static int calcSum(List<Integer> list) { int sum=0; for (int num :list){ sum+=num; } return sum; } public static void PrintAllElements(List<Integer> list) { int print=0; while(!list.isEmpty()){ print = list.remove(0); System.out.print(print+" "); } } public static void main(String[] args) { Scanner s = new Scanner(System.in); List<Integer> numbers = new ArrayList<Integer>(); int counter=0; while (true) { System.out.println("Enter number:"); int num= s.nextInt(); counter++; if (num > 0) numbers.add(num); else if (num ==0) break; } int sum = calcSum(numbers); System.out.println("Sum = "+sum); //System.out.println(counter); for(int i=1;i<=counter;i++) { PrintAllElements(numbers); } } }
, : foreach (int num in list)for (int num :list)
Code:List<Integer> numbers = new ArrayList<Integer>();
Code:while(!list.isEmpty())
.Code:print = list.remove(0);
Last edited by bombov; 17th March 2009 at 22:40.
-
17th March 2009 23:43 #2
,
:
Code:List<int> numbers = new List<int>();
Code:while(list.Count > 0)
PS. List<T> http://msdn.microsoft.com/en-us/library/6sh2ey19.aspxCode:print = list[0]; list.RemoveAt(0);
-
18th March 2009 07:53 #3:Code:
public static void PrintAllElements(List<Int32> list) { int print=0; while(list.Count > 0){ print = list[0]; list.RemoveAt(0); Console.WriteLine(print+" "); } }
, ?Code://counter for (int i = 1; i <= counter; i++) { PrintAllElements(numbers, counter); }
-
18th March 2009 17:58 #4
-
18th March 2009 17:31 #5
, , 1 , ?
, . .
"640K ught to be enough for anybody" - Bill Gates, 1981
::Machine specs::Fract::AGG::::Baileys::blog::YouTube channel
-
18th March 2009 20:53 #6
. 1 .
@Bombera
:
:Code:Console.WriteLine(list[0] + " "); list.RemoveAt(0);
Code:// : Console.Write("Elements are - "); PrintAllElements(numbers);Code:// : public static void PrintAllElements(List<Int32> list) { foreach (int num in list) { Console.Write(num + " "); } }
-
19th March 2009 04:29 #7
-
19th March 2009 00:40 #8
, , , . , .
EVGA X299 FTW K|i9-7960X@4.7|4x8 Patriot Viper Steel 4000|GTX 1660 Ti|970 EVO 1 TB|Seasonic Focus GX-1000|Xigmatek Elysium|
Rampage IV Extreme BE|E5-1680v2@4.7|4x4 HyperX 1866|Cougar Aqua 240|GTX 1050 Ti|970 EVO 1/4 TB|CM 850 SilentPro|HAF-X|
-
19th March 2009 13:48 #9
, ?
EVGA X299 FTW K|i9-7960X@4.7|4x8 Patriot Viper Steel 4000|GTX 1660 Ti|970 EVO 1 TB|Seasonic Focus GX-1000|Xigmatek Elysium|
Rampage IV Extreme BE|E5-1680v2@4.7|4x4 HyperX 1866|Cougar Aqua 240|GTX 1050 Ti|970 EVO 1/4 TB|CM 850 SilentPro|HAF-X|
-
19th March 2009 17:11 #10.Consider for Instead of foreach
Use for instead of foreach (C#) to iterate the contents of arrays or collections in performance critical code, particularly if you do not need the protections offered by foreach.
Both foreach in C# and For Each in Visual Basic .NET use an enumerator to provide enhanced navigation through arrays and collections. As discussed earlier, typical implementations of enumerators, such as those provided by the .NET Framework, will have managed heap and virtual function overhead associated with their use.
If you can use the for statement to iterate over your collection, consider doing so in performance sensitive code to avoid that overhead.
-
20th March 2009 12:19 #11
. .
, , , Console
, foreach , ? ? .EVGA X299 FTW K|i9-7960X@4.7|4x8 Patriot Viper Steel 4000|GTX 1660 Ti|970 EVO 1 TB|Seasonic Focus GX-1000|Xigmatek Elysium|
Rampage IV Extreme BE|E5-1680v2@4.7|4x4 HyperX 1866|Cougar Aqua 240|GTX 1050 Ti|970 EVO 1/4 TB|CM 850 SilentPro|HAF-X|
-
20th March 2009 20:55 #12
foreach Exception. List<T>.Enumerator , foreach List<T>, _version. , .




Reply With Quote

Lenovo ThinkPad 15 IdeaPad 15
5th May 2023, 22:16 in