zzz
zzz
CC#
Created by zzz on 10/11/2024 in #help
changing a boolean value outside a loop from inside a loop
so im doing a leetcode challenge to detect duplicate numbers in an array, im trying to use the duplicate bool value so when a duplicate is detected, it edits the duplicate value to true and exits the loop, no matter what i try the output is always false however
public class Solution
{

int[] nums ={1, 2, 3, 1};

public bool ContainsDuplicate(int[] nums)
{
bool running = true;
bool duplicate = false;
int count = 0;
int count2 = 0;

while (running == true)
{
foreach (int x in nums)
{
foreach (int z in nums)
{

if (z == nums[count])
{
count2++;
break;
}

count++;
}
if (count2 > 1)
{
running = false;
duplicate = true;
}
count2 = 0;

}
running = false;
}
return duplicate;
}
}
public class Solution
{

int[] nums ={1, 2, 3, 1};

public bool ContainsDuplicate(int[] nums)
{
bool running = true;
bool duplicate = false;
int count = 0;
int count2 = 0;

while (running == true)
{
foreach (int x in nums)
{
foreach (int z in nums)
{

if (z == nums[count])
{
count2++;
break;
}

count++;
}
if (count2 > 1)
{
running = false;
duplicate = true;
}
count2 = 0;

}
running = false;
}
return duplicate;
}
}
24 replies
CC#
Created by zzz on 3/26/2024 in #help
adding numbers from a string array
No description
40 replies
CC#
Created by zzz on 3/25/2024 in #help
reading files from a directory
No description
34 replies
CC#
Created by zzz on 3/25/2024 in #help
✅ converting fractions to percentages and getting an output of 0 no matter what?
public static void Percentages()
{
dpPerc = (dpMark / 35) * 100;
obpPerc = (obpMark / 7) * 100;
cpPerc = (cpMark / 100) * 100;
Console.WriteLine(dpPerc);
Console.WriteLine(obpPerc);
Console.WriteLine(cpPerc);
}
public static void Percentages()
{
dpPerc = (dpMark / 35) * 100;
obpPerc = (obpMark / 7) * 100;
cpPerc = (cpMark / 100) * 100;
Console.WriteLine(dpPerc);
Console.WriteLine(obpPerc);
Console.WriteLine(cpPerc);
}
the mark variables were user inputted integers but when i use this method to get percentages, i outputted them to check they were correct and they are always 0?
8 replies
CC#
Created by zzz on 3/25/2024 in #help
✅ cloned a repository but cant push to it
No description
6 replies
CC#
Created by zzz on 3/24/2024 in #help
catching exception but skipping an iteration
No description
11 replies