Jump to content

Jay001

Members
  • Posts

    6
  • Joined

  • Last visited

Everything posted by Jay001

  1. please help
  2. I am a rookie and I am learning Java on my own, so could you please fix my code. Then,I will understand more. Thank you so much!
  3. I tried but is still not working import java.util.Scanner; public class program { public static void main(String[] args) { string score; Scanner scan = new Scanner(System.in); System.out.println("please type your score"); score=scan.nextLine(); if (score>90) { System.out.println("you got an A"); } } } it shows > undefine
  4. which part did I do wrong with my code? import java.util.Scanner; public class program { public static void main(String[] args) { int x; Scanner scan = new Scanner(System.in); System.out.println("please type your score"); x=scan.nextLine(); if (x>90) { System.out.println("you got an A"); } } }
  5. so if I set up int x=0 it is using the current value to calculate? I don't understand why we should use += because the variable is 0
  6. don't understand why we should set up the variable to be 0? public static void main(String[] args) { String recipeName, userInputStr; int userInputInt; int numberOfServings = 0; double totalCalories = 0; double totalFat = 0; double totalCholesterol = 0; double totalCarbohydrate = 0; double totalProtein = 0; Scanner inputStream = new Scanner(System.in); System.out.println(" name of this recipe? "); recipeName = inputStream.nextLine(); System.out.println(" How many servings? "); userInputStr = inputStream.nextLine(); numberOfServings = Integer.parseInt(userInputStr); if (numberOfServings < SERVINGS_MIN || numberOfServings > SERVINGS_MAX) { System.out.println(" Wrong number of servings."); System.exit(-1); } System.out.println("----------List of Possible Ingridients=========="); System.out.println(INDENT + "Food #1: " + FOOD_1_NAME); System.out.println(INDENT + "Food #2: " + FOOD_2_NAME); System.out.println(INDENT + "Food #3: " + FOOD_3_NAME); System.out.println(INDENT + "Food #4: " + FOOD_4_NAME); System.out.println(INDENT + "Food #5: " + FOOD_5_NAME); System.out.println(" How many grams of " + FOOD_1_NAME + "? "); userInputStr = inputStream.nextLine(); userInputInt = Integer.parseInt(userInputStr); if (userInputInt < GRAMS_MIN || userInputInt > GRAMS_MAX) { System.out.println(" Wrong number of grams."); System.exit(-1); } totalCalories += userInputInt * (FOOD_1_CALORIES_P100G / 100.); totalFat += userInputInt * (FOOD_1_FAT_P100G / 100.); totalCholesterol += userInputInt * (FOOD_1_CHOLESTEROL_P100G / 100.); totalCarbohydrate += userInputInt * (FOOD_1_CARBOHYDRYTE_P100G / 100.); totalProtein += userInputInt * (FOOD_1_PROTEIN_P100G / 100.);
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.