好的,我正在尝试创建一个程序,要求用户输入一个单词,然后将该单词存储为变量,然后将其显示为数组.
这是我到目前为止:
package coffeearray;
import java.util.Arrays;
import java.util.Scanner;
import java.lang.String;
import java.util.ArrayList;
public class Main {
public static void main(String[] args) {
String drink;
String coffee;
int [] a =new int[6];
Scanner in = new Scanner(System.in);
System.out.println("Please input the word coffee");
drink = in.next();
Run Code Online (Sandbox Code Playgroud)
所以基本上我需要一些代码,以便存储的单词显示为变量.例如,然后将显示"Coffee",但每个字母都在其自己的行上.
我到处搜索,似乎无法找到如何做到这一点.提前致谢.
首先:s.equals("")和之间有什么区别"".equals(s)?
第二:如果我要执行其中一项功能会怎样?"".substring(1)要么"".charAt(0)
我只是想做一个简单的if陈述,告诉你你得到的个人津贴,取决于你的年龄.Employee课堂上有一个"年龄"的领域,这就是我超越这个年龄的原因.但是我收到错误:对于参数类型Employee,int,运算符>未定义.
我哪里错了?这是我的代码:
double calculatePersonalAllowance(Employee age){
if (this.age < 65) {
personalAllowance = 94440;
}
else if (this.age >= 65 && <75){
personalAllowance = 10500;
}
else if (this.age >75){
personalAllowance = 10660;
return personalAllowance;
}
Run Code Online (Sandbox Code Playgroud) 好的,我有一个简单的数组,我正在使用Java.问题是,当我运行程序时,我得到对象的地址而不是实际值.我也看到循环/数组有问题.它应显示房屋3,5和7,但底部显示3,4和5.我在哪里出错了?请参阅下面的代码和控制台输出.提前致谢!
House[] houses = new House[3];
houses[0] = new House(3,4);
houses[1] = new House(5,7);
houses[2] = new House(7,2);
System.out.println("Number of bottles in house number 3 is: " + houses[0]);
System.out.println("Number of bottles in house number 5 is: " + houses[1]);
System.out.println("Number of bottles in house number 7 is: " + houses[2]);
for (int i = 0; i < houses.length; i++){
System.out.println("Number of bottles in house " + (i + 3 ) + " is " + houses[i]);
}
Run Code Online (Sandbox Code Playgroud)
控制台输出:
3号门的瓶数是:org.com1027.lab3.House@d16e5d6 …