import java.util.Scanner;
public class ShoutandWhisper {
public static void main(String[] args)
{
//defining the variables
String word, word1;
//Input
Scanner kb = new Scanner(System.in);
System.out.print("Give me a word that has 7 letters > ");
word = kb.nextLine();
word1 = word.toUpperCase();
System.out.println("I shout " + word1 + " when I'm excited, but i whisper " + word + " when i can't disturb the neigbours.");
char achar = word.charAt(0);
char bchar = word.charAt(1);
char cchar = word.charAt(2);
char dchar = word.charAt(3); …Run Code Online (Sandbox Code Playgroud) import java.util.Scanner;
public class Multiples {
public static void main(String[] args)
{
int number;
Scanner kb = new Scanner(System.in);
System.out.print("insert a number >");
number = kb.nextInt();
if (number >= 0 && number <= 100)
if (number % 7 == 0)
System.out.println("multiple of 7");
else
System.out.println("not a multiple of 7");
if (number % 2 == 0)
System.out.println(" multiple of 2");
else
System.out.println("not a multiple of 2");
else
System.out.println("choose a different number");
}
}
Run Code Online (Sandbox Code Playgroud)
代码工作正常,直到最后一刻.所有if语句都在接受测试的主IF内部工作.但是当我使用最后一个时,我得到语法错误.谁能告诉我哪里出错了?
java ×2