package assignment_3_1;
import java.util.Scanner;
public class Assignment_3_1 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
//create a scanner
Scanner input = new Scanner (System.in);
//obtain package weight 1
System.out.print("Enter the Package Weight (In Pounds): ");
int packageWeight1 = input.nextInt();
double WeightCalc1 = 5;
double WeightCalc2 = 15;
double WeightCalc3 = 34;
double WeightCalc4 = 45;
double WeightCalc5 = 60;
double WeightCalc6 = 60;
double priceA = 12;
double priceB = 14;
double priceC = 17;
double priceD = 21;
double priceE = 33;
double priceF = 105;
//if WeightCalc1 >= packageWeight1 the base charge is 12
if (WeightCalc1 >= packageWeight1)
{
System.out.println("The Base Charge is : " + priceA);
int basePrice = 12;
}
else
{
//if WeightCalc2 >= packageWeight1 the base charge is 14
if (WeightCalc2 >= packageWeight1)
{
System.out.println("The Base Charge is: " + priceB);
int basePrice = 14;
}
else
{
//if WeightCalc3 >= packageWeight1 the base charge is 17
if (WeightCalc3 >= packageWeight1)
{
System.out.println("The Base Charge is: " + priceC);
int basePrice = 17;
}
else
{
//if weightCalc4 >= packageWeight1 the base charge is 21
if (WeightCalc4 >= packageWeight1)
{
System.out.println("The base charge is: " + priceD);
int basePrice = 21;
}
else
{
//if weightCalc5 >= packageWeight1 the base charge is 33
if (WeightCalc5 >= packageWeight1)
{
System.out.println("The base charge is: " + priceE);
int basePrice = 33;
}
else
{
//if weightCalc6 < packageWeight1 the base charge is 105
if (WeightCalc6 < packageWeight1)
{
System.out.println("The base charge is: " + priceF);
int basePrice = 105;
}
else
{
System.out.println("Re-Run the Program");
}
}
}
}
}
}
//obtain zipCode
System.out.println("Enter your 5 Digit Zip Code: ");
int zipCode = input.nextInt();
double perc1 = 3999;
double perc2 = 5000;
double perc3 = 5999;
double perc4 = 7000;
//if perc1 < basePrice < perc2
if (perc1 < basePrice < perc2)
{
}
}
}
我宣布里面一个int if语句,当我开始后的大写入底部if语句我试着用basePrice我if语句我”的内部声明中的int我尝试改变int的名称,并使用double而不是int,没有任何工作不知道我做错了什么。惯于显示INT宣布if语句
你应该阅读本http://www.java-made-easy.com /variable-scope.html – nem035 2014-10-09 13:32:26
原因是你的int如果只在块内可见,如果您希望basePrice对您的整个主要方法可见,请将其声明在您声明所有重量和价格数据的位置。 – SMA 2014-10-09 13:34:08
在if语句内部声明一个'int basePrice = 0;',如果并且只做一个'basePrice = 17,21 ...'。 – Milaci 2014-10-09 13:35:21