我可以在Window/Linux 32位上安装带有64位的java 1.6吗?
我正在制作一个需要涉及一些错误检查的Java程序.我可以阻止用户输入这样的错误数字输入(假设input
扫描仪已经创建):
while (n == 0){
System.out.println("Can't use 0 as a denominator! Please enter a real, nonzero number");
n = input.nextInt();
}
Run Code Online (Sandbox Code Playgroud)
但是如何阻止用户输入无效字符串?我不能用!=
,因为字符串只能与string.equals()
方法比较,对吧?那么,有一段时间没有循环吗?即:
while !(string.equals("y") || string.equals("n")){
//here have code
}
Run Code Online (Sandbox Code Playgroud)
还是那种性质的东西?
下面的代码运行得很完美.给出正确的输出但是,当我将变量的符号从signed更改为unsigned时,程序会运行到无限循环中.该程序是找到整数的阶乘.在我知道unsigned int的模块化行为的任何地方,任何变量的值都不会消极.
#include<stdio.h>
int main(void)
{
int a[200], i,index, number, next, count, temp, test, x;
scanf(" %d", &test);
while(test--)
{
scanf(" %d", &number);
a[0]=1;
count=1; //1 digit
for(next=2;next<=number;++next)
{
index=0;temp=0;
for(i=0;i<count;++i)
{
x=a[index]*next+temp;
a[index]=x%10;
temp=x/10;
++index;
}
while(temp!=0)
{
a[count++]=temp%10;
temp=temp/10;
}
}
for(i=count-1;i>=0;--i)
printf("%d",a[i]);
printf("\n");
}
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我已经坚持了一段时间了,目标是创建一个阵列来保持卡片,一旦我创建阵列打印出来,唯一的卡片是打印的心脏之王.为什么不迭代?
public class Card
{
// Card suits (provided for your convenience - use is optional)
public static final int SPADES = 0;
public static final int HEARTS = 1;
public static final int CLUBS = 2;
public static final int DIAMONDS = 3;
// Card faces (provided for your convenience - use is optional)
public static final int ACE = 1;
public static final int TWO = 2;
public static final int THREE = 3;
public static final int …
Run Code Online (Sandbox Code Playgroud) 我在App\Http\Controllers\Controller.php中创建了Controller
我使用路由代码
$app->get('api/article','App\Http\Controllers\ArticleController@index');
Run Code Online (Sandbox Code Playgroud)
第一部分:
i=j=k=1;
m = ++i && ++j || ++k;
printf("%d, %d, %d, %d\n", i, j, k, m);
Run Code Online (Sandbox Code Playgroud)
输出:2,2,1,1
第一部分容易理解,这里++i && ++j
先执行,这是真的(和i和j的增量值),所以不需要检查OR运算的下一部分(不需要增量值为k).
第二部分:
i=j=k=1;
m = ++i || ++j && ++k;
printf("%d, %d, %d, %d\n", i, j, k, m);
Run Code Online (Sandbox Code Playgroud)
输出:2,1,1,1
第二部分容易理解,这里++i || ++j
先执行,其中++i
为真(并且增加值i
,因为OR opreation所以不需要增加值j
).接下来执行AND操作这里应该是增量值k=2
(但仍然是k print 1的值).
亲爱的利他主义者,请解释我在第二部分发生的事情.
我用这些命令改变了我的用户和电子邮件git
git config --global user.name "maa"
git config user.email "maa@gmail.com"
Run Code Online (Sandbox Code Playgroud)
我确认了这一变化
git config --global user.name
git config user.email
Run Code Online (Sandbox Code Playgroud)
它显示正确的名称.但是,当我按下旧用户名时使用:
git push -u origin master
remote: Permission to maa/brain.git denied to old_user_name.
fatal: unable to access 'https://github.com/maa/brain.git/': The requested URL returned error: 403
Run Code Online (Sandbox Code Playgroud) 在阅读K&R(第6.5节,第二版)时,我遇到了以下功能:
struct tnode *talloc(void)
{
return (struct tnode *) malloc( sizeof(struct tnode) );
}
Run Code Online (Sandbox Code Playgroud)
该函数分配一些空格来存储struct tnode.我只是想通过询问我是否会达到以下目的来检查我的理解:
struct tnode *talloc(void)
{
struct tnode s;
return &s;
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试编写这个程序来计算存款的简单利息.它应该将利息金额加到原始存款上.
但它继续使变量"速率"0,这就是为什么当我运行它,结果为0.任何帮助表示赞赏.
#include <stdio.h>
int main(void){
double d;
double rate;
double y;
double final;
int x;
printf("Enter the deposit: ");
scanf("%d", &d);
printf("Enter the interest rate (0-100): ");
scanf("%d", &rate);
printf("Enter the number of years: ");
scanf("%i", &x);
rate = rate / 100;
y = d * rate * x;
final = d + y;
printf("After %i number of years, the deposit in the savings account is now %d", x, rate);
}
Run Code Online (Sandbox Code Playgroud) 我有一个类似于以下内容的 HTTP Web 请求:
Dim myrequest As HttpWebRequest = HttpWebRequest.Create("myURL")
myrequest.Proxy = Nothing
myrequest.UserAgent = "AGENT"
myrequest.Method = "POST"
myrequest.ContentLength = 0
myrequest.Headers.Add("KEY1", value)
myrequest.Headers.Add("KEY2", value)
Dim myresponse As HttpWebResponse = myrequest.GetResponse
Dim mystream As System.IO.Stream = (myresponse.GetResponseStream)
Dim streamreader As New System.IO.StreamReader(mystream)
return streamreader.ReadToEnd
Run Code Online (Sandbox Code Playgroud)
问题是我无法发送以下任何值来在标题值中放置换行符。到目前为止,我已经尝试过:
新行
vbCrLf
vbCR
低频
这些会产生一个错误,指出“指定的值具有无效的 CRLF 字符”我也试过
\n
\r\n
它只是将字符串文字添加到我的值中,不包括回车符。在服务器端,我想获取此标题中包含的值并将其放入 MySQL 的列中。
我正在阅读Linux设备驱动程序,并注意到您可以使用printk打印当前行和文件.这是如何实现的?Linux如何跟踪包含printk语句的行?我还没有在用户空间中编写的"普通C代码"中看到类似的功能.
这是LDD3的一个例子:
printk(KERN_DEBUG "Here I am: %s:%i\n", __FILE__, __LINE__);
Run Code Online (Sandbox Code Playgroud)
编辑:正如piokuc所说,这些实际上是标准的宏.GCC文档在这里描述它们:http://gcc.gnu.org/onlinedocs/cpp/Standard-Predefined-Macros.html
__CODE__
为每一行设置并由预处理器替换为当前行,__CODE__
为每个文件设置.
我正在为我的java类做一个作业,我们刚开始学习HashMaps,我们有这个作业,我们创建枚举数据并将其存储在一个hashmap中以便稍后打印出来.我可以想象的是能够打印HashMap的元素.到目前为止,这是我的项目:
public class Driver <enumeration>
{
private static HashMap<String, State> stateList = new HashMap<String, State>();
public static void main(String args[]) throws IOException
{
stateList.put("1", State.CA);
stateList.put("2", State.FL);
stateList.put("3", State.ME);
stateList.put("4", State.OK);
stateList.put("5", State.TX);
for(State value : stateList.values())
{
System.out.println(value);
}
}
}
public enum State
{
CA(new StateInfo("Sacramento", 38802500)), FL(new StateInfo("Tallahassee", 19893297)),
ME(new StateInfo("Augusta", 1330089)), OK(new StateInfo("Oklahoma City", 3878051)),
TX(new StateInfo(" Austin", 26956958));
private StateInfo info;
private State(StateInfo info)
{
this.info = info;
}
public StateInfo getInfo()
{
return info; …
Run Code Online (Sandbox Code Playgroud) c ×5
java ×4
c++ ×1
calculator ×1
expression ×1
git ×1
github ×1
hashmap ×1
http ×1
http-headers ×1
kernel ×1
laravel ×1
linux ×1
loops ×1
lumen ×1
malloc ×1
pointers ×1
struct ×1
vb.net ×1
while-loop ×1