最后一行不打印?

时间:2018-06-16 02:53:23

标签: java

当我运行程序时,一切正常,直到我到达最后一行,我想根据类型增加气体价格,但该部分不会打印出来。

{
public static void main(String[] args)
{

double R = 2.19;
double M = 2.49;
double P = 2.71;

System.out.println("What type of gas?");
System.out.println("(R)egular:    2.19");
System.out.println("(M)idgrade:   2.49");
System.out.println("(P)remium:    2.71");

 String gastype;
 gastype = S.nextLine();

 System.out.println("How many gallons?");
 double gallons;
 gallons = S.nextDouble();

 if ((R * gallons) == 0)
 {
   System.out.println("You owe: " +R * gallons+ "");
 }

 if ((M * gallons) == 0)
 {
   System.out.println("You owe: " +M * gallons+ "");
 }

 if ((P * gallons) == 0)
 {
   System.out.println("You owe: " +P * gallons+ "");
  }
 }
}

3 个答案:

答案 0 :(得分:1)

要让您的代码段打印ffi_type_sint,它应该类似于:

#include <ffi.h>
#include <gtk/gtk.h>

void test(void);

int main(void) { test(); }

void test(void) {
  ffi_type *arg_types[] = {&ffi_type_pointer, &ffi_type_pointer};
  ffi_cif cif;
  ffi_status status =
      ffi_prep_cif(&cif, FFI_DEFAULT_ABI, sizeof arg_types / sizeof *arg_types,
                   &ffi_type_void, arg_types);
  if (status != FFI_OK) {
    printf("Failed to prep_ffi\n");
    return;
  }

  // bad we don't check malloc() !!! ;)
  int argc = 4;
  char **argv = malloc(sizeof *argv * (argc + 1));
#define X(x) strcpy(malloc(sizeof x), x);
  argv[0] = X("test");
  argv[1] = X("--gtk-debug");
  argv[2] = X("misc");
  argv[3] = X("last");
  argv[4] = NULL;
#undef X

  int *p_argc = &argc; // This is what expect gtk_init
  char ***p_argv = &argv;
  void *arg_values[] = {&p_argc, &p_argv}; // so ffi need their address

  ffi_arg result;
  ffi_call(&cif, FFI_FN(&gtk_init), &result, arg_values);

  for (int i = 0; i < argc; i++) {
    printf("%s\n", argv[i]);
    free(argv[i]);
  }

  free(argv);
}

答案 1 :(得分:0)

只有当加仑数为0时,您的if语句才会执行。不仅如此,您还没有检查客户想要的气体。你基本上完全忽略gastype作为你的最终答案。

以此if语句为例

if (gasType.equals(“Regular”) {
  //Stuff you want to print
}

答案 2 :(得分:0)

使用此

public static void main(String[] args) {
double R = 2.19;
double M = 2.49;
double P = 2.71;

System.out.println("What type of gas?");
System.out.println("(R)egular:    2.19");
System.out.println("(M)idgrade:   2.49");
System.out.println("(P)remium:    2.71");

 String gastype;
 gastype = S.nextLine();

 System.out.println("How many gallons?");
 double gallons;
 gallons = S.nextDouble();

 if ((gasType == 'R') {
   System.out.println("You owe: " +R * gallons+ "");
 }
 else if (gasType == 'M') {
   System.out.println("You owe: " +M * gallons+ "");
 }
 else if (gasType == 'P') {
   System.out.println("You owe: " +P * gallons+ "");
 }
 else {
   System.out.println("Wrong GasType")
 }
}