我有一个文件questions.php与数组如下:
$question12 = array("Which is the tallest mountain","Mt Everest");
Run Code Online (Sandbox Code Playgroud)
我在另一个文件中使用此文件如下:
require_once('questions.php');
$var = 12;
$question = '$question'.$var.'[0]';
echo $question;
Run Code Online (Sandbox Code Playgroud)
上面的代码只输出字符串
$question12[0]
Run Code Online (Sandbox Code Playgroud)
但我希望变量$ question让字符串出现在$ question12 [0]中.
怎么做..??
我正在尝试生成一组点,当绘制为图形时,这些点代表 1 个周期的正弦波。要求是:
代码 :
int main()
{
ofstream outfile;
outfile.open("data.dat",ios::trunc | ios::out);
for(int i=0;i<100;i++)
{
outfile << int(3276*sin(i)+32767) << "\n";
}
outfile.close();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我正在生成并将点存储在文件中。绘制这些点后,我得到下图。
但我只需要一个周期。我怎样才能做到这一点?
我希望以下程序的输出为5,但编译器显示20.有人可以解释一下原因吗?
#include <stdio.h>
int a=5;
change1(int *p);
int main(void)
{
int x=20,*ptr=&x;
change1(ptr);
printf("%d ",*ptr);
return 0;
}
change1(int *p)
{
p=&a;
}
Run Code Online (Sandbox Code Playgroud) 这是我的代码,用于检查一组分组字符是否正确平衡.它在我的本地机器上工作正常,但在线判断给我一个运行时错误.
#include <iostream>
#include <string>
#include <stack>
using namespace std;
bool balanced(string exp)
{
stack<char> st;
int i;
for(i=0;i<exp.length();i++)
{
if(exp[i]== '{' || exp[i]=='[' || exp[i]== '(') st.push(exp[i]);
else if(exp[i]=='}'){
if(st.top() == '{' && !st.empty()) st.pop();
else return false;
}
else if(exp[i]==')'){
if(st.top() == '(' && !st.empty()) st.pop();
else return false;
}
else if(exp[i]==']'){
if(st.top()=='[' && !st.empty()) st.pop();
else return false;
}
}
if(st.empty())return true;
else return false;
}
int main() {
string exp;int n;
cin >> n;
cin.ignore();
while(n--) …Run Code Online (Sandbox Code Playgroud) 我有一个简单的线性布局,里面有2个按钮.
我设置了layout_width ="fill_parent"
但我希望按钮占据屏幕尺寸的70%,同时我希望它们居中.
我如何实现这一目标.
这就是它现在的样子.

我想要这样的东西.

谢谢.
编辑: XML代码如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:id="@+id/button2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) 该程序返回一个指向结构的指针.
当我打印内容时,名称未正确显示,其他两个变量正在正确打印.
可能是什么问题呢?这是C中的代码
#include<stdio.h>
struct student
{
char name[20];
int marks;
int rank;
};
struct student stu;
struct student *create();
void main()
{
struct student *ptr;
ptr = create();
printf("%s\t %d\t %d\t",ptr->name,ptr->marks,ptr->rank);
}
struct student *create()
{
struct student stu = {"john",98,9};
struct student *ptrr;
ptrr = &stu;
return ptrr;
}
Run Code Online (Sandbox Code Playgroud) 我试图用Java连接到数据库.这是一个简单的程序.
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost/servlets","root","");
smt = con.createStatement();
query = "select pass from users where uname = "+uname;
System.out.println(query);
rs = smt.executeQuery(query);
if((rs.getString("pass"))==pass){
out.println("correct pass...logged in..");
}
else {
out.println("Incorrect pass...not logged in..");
}
Run Code Online (Sandbox Code Playgroud)
但它说
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:您的SQL语法中有错误; 查看与您的MariaDB服务器版本对应的手册,以便在第1行的"@ gmail.com"附近使用正确的语法
我正在尝试验证特定电子邮件ID的密码.
我在 PHP 中创建了一个数组,如下所示:
$arr = array(123,144,144,123);
如何获得每个值出现的第一个和最后一个索引。
就像是,
123 -> first occurrence - 0th index | last occurrence - 3rd index
144 -> first occurrence - 1st index | last occurrence - 2nd index
Run Code Online (Sandbox Code Playgroud)