在 xml 中,我试图让按钮位于右侧。这是我的代码。
<TableRow>
<Button
android:layout_gravity="right"
android:gravity="right"
android:id="@+id/Button01"
android:text="Sign in" />
</TableRow>
Run Code Online (Sandbox Code Playgroud)
当我删除 tableRow 标签时,按钮会占据屏幕的整个宽度。我也尝试过从右到左的改变,但仍然没有运气
我使用枚举作为我的switch语句的选项,它的工作原理.问题是如果用户输入无效选项,程序崩溃.我应该添加什么以便使用默认值?
我的枚举课
public enum Options : byte
{
Display = 1,
Add,
Toggle,
Max,
Mean,
Medium,
Exit
}
Run Code Online (Sandbox Code Playgroud)
在主我的switch语句中
string volString = Console.ReadLine();
Options options = (Options)Enum.Parse(typeof(Options), volString);
// this is the line that is giving me the runtime error. Since other options are not found
Run Code Online (Sandbox Code Playgroud)
在枚举程序崩溃.
switch (options)
{
case Options.Display: //dispaly regular time
case Options.Toggle://toggle
default:
Console.WriteLine("entry blah blah");
break;
Run Code Online (Sandbox Code Playgroud) 为了澄清,多个学生对象和所有对象都获得了相同的价值.
我知道之前已经问过这个问题,但我对其他关于他主题的帖子没有运气.我有一个1-3的随机数发生器.我然后我们%2使bool值为true或false.每次我运行程序时,我要么全部都是真的,要么都是假的.这是我的代码.我知道随机并不是随机的.我该怎么做才能获得更多随机数.
Random random = new Random();
public Student()
{
int randomLevel=random.Next(1,3);
level = (randomLevel % 2 == 0);
}
public bool readingLevel()//this always returns one value for the entire program.
{
return level;
}
Run Code Online (Sandbox Code Playgroud) 我正在编写一个小shell程序,它接受一个命令并执行它.如果用户输入无效命令,则if语句返回-1.如果命令正确则执行命令,但是一旦执行命令,程序就会结束.我做错了什么不会在它之后执行代码行?我用ls和cat命令测试了execvp(command.argv [0],command.argv),所以我很确定它有效.这是我的代码.
int shell(char *cmd_str ){
int commandLength=0;
cmd_t command;
commandLength=make_cmd(cmd_str, command);
cout<< commandLength<<endl;
cout << command.argv[0]<< endl;
if( execvp( command.argv[0], command.argv)==-1)
//if the command it executed nothing runs after this line
{
commandLength=-1;
}else
{
cout<<"work"<<endl;
}
cout<< commandLength<<endl;
return commandLength;
}
Run Code Online (Sandbox Code Playgroud) 当我使用char调用gethostname我的长度为25但是当我使用字符串时我的长度是64.不确定为什么.他们两个我在HOST_NAME_MAX上声明了相同的大小.
char hostname[HOST_NAME_MAX];
BOOL host = gethostname(hostname, sizeof hostname);
expectedComputerName = hostname;
int size2 = expectedComputerName.length();
std::string test(HOST_NAME_MAX, 0);
host = gethostname(&test[0], test.length());
int testSize = test.length();
Run Code Online (Sandbox Code Playgroud) 我试图使用if语句来使用bool值,但它不起作用.顶部是我正在使用的函数,底部是if语句.当我将if语句更改为false时,我得到结果,但我需要true和false bools.有小费吗
public function find($key) {
$this->find_helper($key, $this->root);
}
public function find_helper($key, $current){
while ($current){
if($current->data == $key){
echo " current";
return true;
}
else if ($key < $current->data){
$current= $current->leftChild;
//echo " left ";
}
else {
$current=$current->rightChild;
//echo " right ";
}
}
return false;
}
if($BST->find($randomNumber)){//how do I get this to return a true value?
echo " same ";
}
Run Code Online (Sandbox Code Playgroud) 我接受了采访,但我无法回答这个问题.您有一个二叉树,并且您使用in_order将所有节点放入一个数组中,并返回该数组大小的值.我被告知我无法使用辅助函数并为数组计数器添加int i = 0.
我必须使用的递归函数标题是.
In_order(Struct_Node * node, int *array){
}
Run Code Online (Sandbox Code Playgroud)
因为我写的是In_order.
if(node){
In_order(node->left, array);
Run Code Online (Sandbox Code Playgroud)
//这行是我应该添加元素并返回值的地方,但我不明白该怎么做.这是我的周点,我需要理解这段代码的工作原理比代码更多.
in_order(node->right,array);
}
Run Code Online (Sandbox Code Playgroud)
我实际上并没有写出我在两个In_order语句之间写的内容,但我写的是错误的.
我有一分钟和一分钟.迭代数组我需要删除min和max之间的所有元素.我不能使用任何内置的数组函数,如splice,数组需要保持原始顺序.例如,数组[1,5,13,27,58] min = 10 max = 30将返回[1,5,58]的数组.我正在寻找更多关于如何在N时间复杂度中做到这一点的策略.这个问题是面试准备.
这是我试过的代码,
function filter_range(array, min, max) {
for (var i = 0; i < array.length; i++) {
if (min < array[i] && array[i] < max) {
for (var j = i; j < array.length - 1; j++) {
var temp = array[j]
array[j] = array[j + 1];
array[j + 1] = temp;
}
}
}
}
var array = [1, 5, 23, 13, 59];
filter_range(array, 10, 30);
for (var i = 0; i < …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用我在控制器中设置的变量作为 img 标签内的 src。我直接复制了字符串并且它起作用了,所以我知道我的路径是正确的。但是,我无法弄清楚如何将我创建的变量放入 img 标签中。
这是我的控制器:
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
namespace dojodachi.Controllers
{
public class HomeController : Controller
{
// GET: /Home/
[HttpGet]
[Route("")]
public IActionResult Index()
{
ViewData["Tree"] = "~/images/regular_tree.jpeg";
return View();
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的 cshtml 文件
<div id = wrapper>
<p>Fullness: Happiness: Meals: Energy</p>
<div id = inside>
<img src="@ViewData['Tree']" alt="Regular Tree"> //How do I place my variable in this img tag?
<p></p>
</div>
</div>
Run Code Online (Sandbox Code Playgroud) 在我的 html 中,我有一个 Iframe,它是一个指向 google 文档的链接。目前,用户将能够编辑文档。但是,我不希望用户能够更改文档。我如何使 iframe 只读?