我正在为学校做作业,如果我在某一天加上折扣,我会得到奖励分数.我有一个主动更新时间,使用日期函数(它是一个函数?)但我不知道如何为此制作一个if语句.
这是我的代码:
<?php
$t = time();
echo "Date of Purchase: " . (date("Y-m-d", $t));
if(date == "20140224") {
echo $b;
echo "It works!";
}
?>
Run Code Online (Sandbox Code Playgroud)
显然我只提供了相关的代码.任何帮助表示赞赏!
我有一个家庭作业,要求我编写一个计算输入行中点数的程序.到目前为止,这是我所提出的它的工作(有点),除了它计算一切而不是只有点.我坚持如何让程序只计算点数.
import javax.swing.*;
import java.lang.Character;
public class Assign5_Polk {
public static void main(String[] args) {
String string = JOptionPane.showInputDialog("Give me dots and i will count them : ");
int count = 0;
for (int i = 0; i< string.length(); i++) {
char c = string.charAt(i);
if (string.contains(".")) {
count++;
}
}
System.out.println("There are" + " "+ count + " " + "dots" +" " + "in this string. " + string);
}
}
Run Code Online (Sandbox Code Playgroud) 哪一个更快更好?编写自己的函数或在php中使用内置函数.用于将2D阵列转换为1D阵列.我必须使用
array_merge($array1)
Run Code Online (Sandbox Code Playgroud)
或者使用自己编写的函数
foreach(){
}
Run Code Online (Sandbox Code Playgroud) 下面的代码询问用户他/她想要多少赛车手.
while (true) { // loops forever until break
try { // checks code for exceptions
System.out.println("How many racers should" + " participate in the race?");
amountRacers = in.nextInt();
break; // if no exceptions breaks out of loop
}
catch (InputMismatchException e) { // if an exception appears prints message below
System.err.println("Please enter a number! " + e.getMessage());
continue; // continues to loop if exception is found
}
}
Run Code Online (Sandbox Code Playgroud)
如果在amoutnRacers = in.nextInt();代码中输入一个数字,则循环出来并且程序的其余部分运行正常; 但是,当我输入诸如"awredsf"之类的内容时,它应该捕获该异常,它会这样做.而不是再次提示用户它不断循环,这对我来说没有意义.
程序在连续循环时打印如下:
有多少参赛者应参加比赛?有多少参赛者应参加比赛?有多少参赛者应参加比赛?有多少参赛者应参加比赛?有多少参赛者应参加比赛?有多少参赛者应参加比赛?有多少赛车手参加比赛?请输入一个号码!null请输入一个数字!null请输入一个数字!null请输入一个数字!null请输入一个数字!null请输入一个数字!null请输入一个数字!空值 ...
我不明白发生了什么amountRacers …
java exception-handling try-catch while-loop inputmismatchexception
我写了这段代码,它应该搜索素数并将它们放入数组中.这里是:
int[] prime_array = new int[(int)s.upper_bound];
int index_in_array = 0;
boolean are_we_done = false;
int index = 1;
boolean is_prime = true;
while (!are_we_done) {
try {
for (int i = 1; i < index; i++) {
if ((index%i)==0) {
is_prime = false;
}
}
if (is_prime) {
prime_array[index_in_array] = index;
index_in_array++;
}
index++;
is_prime = true;
}
catch (IndexOutOfBoundsException e) {
are_we_done = true;
break;
}
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,它捕获的唯一主要是1.任何想法为什么它不起作用?
我有一个像这样的int的Scanner
Scanner telnumscanner = new Scanner(System.in);
System.out.print("Entrez phone number: \n");
int telnum = telnumscanner.nextInt();
Run Code Online (Sandbox Code Playgroud)
我在那里输入了一个电话号码样式(0000000000--10个数字)但是当我输入号码时,它会崩溃.
为什么我们可以创建多个静态类的实例?我试图在静态类和静态方法之间找到相似之处,但这个事实让我感到困惑。
class Hello {
public static void main(String args[]) {
int i = 10;
i *= i++ + i;
System.out.println(i);
}
}
Run Code Online (Sandbox Code Playgroud)
根据运算符的优先级,后缀运算符的优先级高于乘法运算符。括号内的操作数具有更高的优先级。
首先评估它们: i*(i++ + i) 所以,现在,括号内是 10+11: i*(21)
i 的当前值为 11
其次,由于下一个优先级计算乘法运算符,它不应该是11*21=231吗?
虽然,我知道答案是 210,为什么我上面解释的逻辑是错误的?
编写.querySelectorAll()代码以查找作为具有类的元素的后代的所有段落元素:articles
找到所有这些元素的代码是什么?我试过
document.querySelectorAll("p>.articles")
Run Code Online (Sandbox Code Playgroud)
它不起作用。
我需要创建一个程序来读取文本文件并打印以下内容:
from collections import Counter
count = 0
file = open(r"sample_input.txt", "r", encoding="utf-8-sig")
wordcount = Counter(file.read().split())
for item in wordcount.items():
print("{}\t-\t{}".format(*item))
Run Code Online (Sandbox Code Playgroud)
输出应如下所示:
WORD FREQUENCY
can - 1
grow - 1
and - 1
shrink - 1
on - 1
demand - 1
TOTAL = 6
Run Code Online (Sandbox Code Playgroud)
我的程序对小写和大写的计数不同。有没有办法过滤出标点符号?
java ×6
php ×2
class ×1
date ×1
integer ×1
javascript ×1
primes ×1
python ×1
try-catch ×1
while-loop ×1