我是初学者.....我似乎无法解决涉及多种方法的问题....使用扫描仪的方法没有做任何事情
package bucky;
import java.util.Scanner;
public class test {
public static void main(String args[]){
input();
for(int time=1;time<values[2];++time){
double A=values[1]*Math.pow(1+values[3], time);
System.out.println("You have: "+A+ " subscribers today");
}}
public static double[] input(){
Scanner s=new Scanner(System.in);
double[] values=new double[3];
System.out.println("Enter the Principal value: ");
values[1]=s.nextDouble();
System.out.println("Enter the no. of days: ");
values[2]=s.nextInt();
System.out.println("Enter the Rate of growth : ");
values[3]=s.nextDouble();
return values;
}
}
答案 0 :(得分:2)
values
分配给double[] values = input();
吗?喜欢:public static void main(String args[])
{
double[] values = input();
for (int time = 1; time < values[2]; ++time)
{
double A = values[1] * Math.pow(1 + values[3], time);
System.out.println("You have: " + A + " subscribers today");
}
}
public static double[] input()
{
Scanner s = new Scanner(System.in);
double[] values = new double[3];
System.out.println("Enter the Principal value: ");
values[0] = s.nextDouble();
System.out.println("Enter the no. of days: ");
values[1] = s.nextInt();
System.out.println("Enter the Rate of growth : ");
values[2] = s.nextDouble();
return values;
}
此外,数组中的索引以0开头...因此值[0]是第一个值,依此类推。
试试这段代码:
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />
答案 1 :(得分:0)
尝试double [] values = input();在主要方法。
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class test { public static void main(String args[])
{
double[] values = input();
for(int time=1;time<values[2];++time){
double A=values[0]*Math.pow(1+values[2], time);
System.out.println("You have: "+A+ " subscribers today");
}}
public static double[] input()
{
Scanner s=new Scanner(System.in);
double[] values=new double[3];
System.out.println("Enter the Principal value: ");
values[0]=s.nextDouble();
System.out.println("Enter the no. of days: ");
values[1]=s.nextInt();
System.out.println("Enter the Rate of growth : ");
values[2]=s.nextDouble();
return values;
}
}
同样,它会抛出一个数组输出错误...用values[1]
values[0]
和values [2]
values[1]
和values[3]
更改values[2]
。