我的声明正在发挥作用:
import java.util.*;
public class Recursion{
public static int sumOfInt(int x)
{
int sum =0;
if (x <= 1)
return x;
else
sum += x % 10;
x /= 10;
return sum + sumOfInt(x);
}
public static void main (String [ ] arg){
Scanner sc = new Scanner(System.in);
int userInt = 0;
boolean userInput = false;
boolean endLoop = false;
String userAgain = "";
do{
do{
try{
System.out.print("Please enter an integer number: ");
userInt = sc.nextInt();
userInput = true;
}
catch(InputMismatchException ime) {
System.out.println("You did not enter an integer number");
sc.nextLine();
}
}while(userInput == false);
System.out.println("The integer you entered is " + userInt);
System.out.println("The sum of the digits in the integer you entered is " + sumOfInt(userInt));
System.out.println();
System.out.println("Enter yes to try again");
userAgain = sc.nextLine();
// I don't understand why the above line is not waiting for a user response before quitting.
if(userAgain == "yes"){
endLoop = false;
}else{
endLoop = true;
}
}while(endLoop == false);
}
}
我试图做这样的事情,但它不起作用:
CASE [Level 1]
WHEN '2017' THEN ''
WHEN '2016' THEN ''
WHEN '2015' THEN ''
WHEN '2014' THEN ''
ELSE [Level 1]
END
关于如何使第二个陈述有效的建议?
答案 0 :(得分:1)
你想要这样的东西:
CASE WHEN [LEVEL 1] LIKE 'CALENDAR MONTH%' THEN 'CALENDAR MONTH'
WHEN [LEVEL 1] LIKE 'CALENDAR WEEK%' THEN 'CALENDAR WEEK'
WHEN [LEVEL 1] LIKE 'CALENDAR QUARTER%' THEN 'CALENDAR QUARTER'
ELSE [LEVEL 1]
END