我试图在3个条件下使用switch语句.条件是:
当我试图运行我的程序时,它显示错误的结果.我的意见是
a = 0
b = 0
c = 0
Run Code Online (Sandbox Code Playgroud)
所以它应该打印"x的任何值是一个解决方案",但它没有.
我的计划是:
#include <stdio.h>
//Function declarations
void getData (int* a, int* b, int* c);
float calculateX (int a, int b, int c);
//===================================================
int main (void)
{
//Local declarations
int a;
int b;
int c;
float x;
//Statements
getData (&a, &b, &c);
calculateX (a, b, c);
int temp;
printf("\nEnter an integer and press enter to exit the program: ");
scanf("%d", &temp);
return 0;
} …Run Code Online (Sandbox Code Playgroud) 我最近在我的Ubuntu上安装了Java SE 7并尝试使用switch on string编译代码,但是无法做到这一点.我从命令行编译.为什么?
java -version
java version "1.7.0"
Java(TM) SE Runtime Environment (build 1.7.0-b146)
Java HotSpot(TM) Server VM (build 21.0-b16, mixed mode)
Run Code Online (Sandbox Code Playgroud)
incompatible types
found : java.lang.String
required: int
switch(attributes.getValue("tod")){
^
1 error
Run Code Online (Sandbox Code Playgroud) 对于那些回答或查看我之前关于休息的问题的一些人来说,这个问题似乎很熟悉; 声明.如果案例1得到满足,我想做点什么,如果是案例2,我想做点别的事情.如下所示.任何人都可以指导我(如果它是可行的)如何实现我正在尝试做的事情,而不是必须将我的if语句放在开关案例中?
switch (searchType)
{
case "SearchBooks":
Selenium.Type("//*[@id='SearchBooks_TextInput']", searchText);
Selenium.Click("//*[@id='SearchBooks_SearchBtn']");
break;
case "SearchAuthors":
Selenium.Type("//*[@id='SearchAuthors_TextInput']", searchText);
Selenium.Click("//*[@id='SearchAuthors_SearchBtn']");
break;
}
int count = int(Selenium.GetXpathCount("//[@id='Results_Table']");
if case was "SearchBooks"
{
//do something
}
else if case was "SearchAuthors"
{
//do something else
}
Run Code Online (Sandbox Code Playgroud) 为什么我得到第92行是无法访问的语句的错误?基本上我要做的是跳过一些代码,如21-22-23 ...如果用户输入类似11-12-13的东西......
import java.util.*;
public class Words {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out. print ("\n\tINTEGER TO WORDS") ;
System.out.print ("\n\nEnter a number between 1 and 9999: ") ;
int num = s.nextInt();
System.out. print ("\nThe answer is: ") ;
int tho = (num - (num % 1000)) ;
int h = (num - tho - (num % 100)) ;
int t = (num - tho - h - (num % 10)) ;
int …Run Code Online (Sandbox Code Playgroud) 我有以下功能正常工作,除了你使用输入值为0时我试过去看看0是否等同为NULL或者我做错了什么.
当输入零时,它输出高于20的高级值.任何人都可以解释一下吗?谢谢
我打算让开关等于0-10,11-20,21-30,31-40,41 +但是对于这个例子我只是使用了两个场景.谢谢
**编辑我确实想要值20 :)
function strengthPlan( $data ) {
$data = ( int ) $data;
switch( $data ) {
case( $data <= 19 ):
$result = 'standard strength';
break;
case( $data >= 20 ):
$result = 'advanced strength';
break;
}
return $result;
}
echo strengthPlan( 0 );
Run Code Online (Sandbox Code Playgroud) 我希望有人知道为什么我得到以下输出,因为我期待别的东西.
$x = NULL;
switch ($x) {
case "0":
echo "String";
break;
case 0:
echo "Integer";
break;
case NULL:
echo "NULL";
break;
case FALSE:
echo "Boolean";
break;
case "":
echo "Empty string";
break;
default:
echo "Something else";
break;
}
// outputs "Integer" was expecting "NULL"
$x=6;
switch ($x) {
case "6b":
echo "6b";
break;
case "6":
echo "6 empty";
break;
case 6:
echo "6 full";
break;
default:
echo "6 half";
break;
}
// outputs "6b" was expecting "6 empty"
Run Code Online (Sandbox Code Playgroud) 这是switch语句.仅当变量$thumbs_number小于-1(例如-2,-3,-4等)时,才bad应输出类.
但是现在,bad当$thumbs_number0为-1 时,类也被输出(-1和1具有正确的类:) average.
<div class="topic-like-count
<?php // Apply style based on number of votes
switch ($thumbs_number) {
case ($thumbs_number < -1): echo ' bad'; break;
case ($thumbs_number == 0):
case ($thumbs_number == 1): echo ' average'; break;
case ($thumbs_number == 2):
case ($thumbs_number == 3): echo ' good'; break;
case ($thumbs_number == 4):
case ($thumbs_number == 5): echo ' great'; break;
case ($thumbs_number == 6):
case ($thumbs_number == 7): echo …Run Code Online (Sandbox Code Playgroud) 我的switch语句只是循环.它应该打印您选择的选项,然后重新打印菜单.请帮忙!这是我的代码:
menu ="\n\t1 Create Account" +
"\n\t2 Check balance" +
"\n\t3 Withdraw" +
"\n\t1 Deposit" +
"\n\t2 Get account ID" +
"\n\t3 Set ID" +
"\n\t1 Display Account Info" +
"\n\t0 Quit\n\n\n";
System.out.println(menu);
System.out.println("\tEnter your selection: ");
option = scan.nextInt();
while (option != 0) {
switch (option) {
case 1: // Enter and Validate SSN
System.out.print("option 1");
break;
case 2: //Enter and Validate Passwords
System.out.print("option 2");
break;
case 3: //Enter,Verify, and Translate a Phone keypad Number
System.out.print("option 3");
break;
case …Run Code Online (Sandbox Code Playgroud) 我有一个很长的问题.我正在创建一个银行帐户并将余额设置为0.如果用户选择提取或存入资金到帐户,则余额永远不会更改.我选择显示余额,它仍然说0.这可能是一个没脑子,但我现在就花了.这是我的长代码(switch语句在我的主类中,方法在对象类中):
public class MyProgram2{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
Scanner input = new Scanner (System.in);
String menu, outputString, poo;
int option = 1;
int id = 0;
double balance = 0, amount = 0;
Account acc = new Account();
menu ="\n\t1 Create Account and ID" +
"\n\t2 Check balance" +
"\n\t3 Withdraw" +
"\n\t4 Deposit" +
"\n\t5 Get account ID" +
"\n\t6 Display Account Info" +
"\n\t0 Quit\n\n\n";
System.out.println(menu);
System.out.println("\tEnter your selection: ");
option = …Run Code Online (Sandbox Code Playgroud) 我正在重构朋友写的一些代码,最近偶然发现了这个函数:
def setup_parameters(self, data):
'''Parse raw data to determine game settings.'''
for line in data.split('\n'):
line = line.strip().lower()
if line:
tokens = line.split()
self.L.debug("tokens: " + str(tokens))
key = tokens[0]
if key == 'cols':
self.width = int(tokens[1])
elif key == 'rows':
self.height = int(tokens[1])
elif key == 'player_seed':
random.seed(int(tokens[1]))
elif key == 'turntime':
self.turntime = int(tokens[1])
elif key == 'loadtime':
self.loadtime = int(tokens[1])
elif key == 'viewradius2':
self.viewradius2 = int(tokens[1])
elif key == 'attackradius2':
self.attackradius2 = int(tokens[1])
elif key == …Run Code Online (Sandbox Code Playgroud) switch-statement ×10
java ×4
php ×3
c ×1
c# ×1
command-line ×1
comparison ×1
java-7 ×1
loops ×1
methods ×1
python ×1
selenium ×1