Question

When I run my program it gives me these exceptions and I don't know what it...

When I run my program it gives me these exceptions and I don't know what it means by it :
Exception in thread "main" java.lang.NumberFormatException: For input string: "Code" Does anyone know what I need to change for this to work?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

NumberFormatException occurs when you are giving a string input for an integer or a double or float variable

For Example -

int num = Integer.parseInt(scan.nextLine());

will cause an exception if you enter "code" or any other string instead of an integer because it tries to parse it as an integer

Add a comment
Know the answer?
Add Answer to:
When I run my program it gives me these exceptions and I don't know what it...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I don't really see a sign that there's error in my code, but when i run...

    I don't really see a sign that there's error in my code, but when i run it I see these. ----------TESTING CONSTRUCTORS-------------- Exception in thread "main" java.lang.ArithmeticException: / by zero    at hw2.Fraction.greatestCommonDivisor(Fraction.java:224)    at hw2.Fraction.reduceToLowestTerms(Fraction.java:209)    at hw2.Fraction.(Fraction.java:44)    at hw2.Fraction.main(Fraction.java:285 What does this mean? I'm currently coding a java program on Fractions. 1. The thing I'm confused are I definitely know there's no error in greatestCommonDivisor and reducedToLowestTerms as those were the codes provided by the instructors and...

  • when i run it is still be "false" i don't know why. could you help me...

    when i run it is still be "false" i don't know why. could you help me fix it and tell me which part is wrong??? specific answer is better thanks!!! Problem 6: (4 pts): Write a function that takes as an input parameter a string. It should return a Boolean value indicating whether the string is a palindrome or not. INPUT: “mom"->true “palindrome”->false “amanaplanpanama"->true 3 #include <iostream> #include <string.h> I using namespace std; string function(string str); int main() { function("palindrome");...

  • Consider the following code. while (!(productCode >= MIN_PRODUCT_CODE) || !(productCode <= MAX_PRODUCT_CODE)) { System.out.println("!!! Invalid product...

    Consider the following code. while (!(productCode >= MIN_PRODUCT_CODE) || !(productCode <= MAX_PRODUCT_CODE)) { System.out.println("!!! Invalid product code"); System.out.print("Enter product code:"); productCode = Integer.parseInt(input.nextLine()); } My question is ... how you keep entering user until is valid? When I entered any number that is invalid input, works fine. I keep entering input value. However, when I entered A , it terminates the program. How do I keep entering the user even if the inputs are String? Enter product code: a Exception...

  • Can anyone help me with this lab? Thanks The BankAccount.h: The BankAccount.cpp: Exceptions Lab In this...

    Can anyone help me with this lab? Thanks The BankAccount.h: The BankAccount.cpp: Exceptions Lab In this lab you will get practice with exceptions by adding them to a class that represents bank accounts. I have provided two files, BankAccount.h and BankAccount.cpp, which have the code for the class itself. Your task is to modify the code to have it throw exceptions under the conditions listed below, then write a main which uses try/catch blocks to display error messages when the...

  • When I try to run the program it gives me an erron saying Expected expresion on...

    When I try to run the program it gives me an erron saying Expected expresion on this line, else if(phrase.find(sub_String)!=std::string::npos). #include #include #include using namespace std;    int main( ) {          // Defining variables. //Initilizing variables. int magicNum; int magicNum1; int position; int phraseLenght; string vowels = "aeiou"; string phrase; string sub;       // The phrase and the sub phrase cout << "Enter a phrase:" << endl; std::getline (std::cin,phrase);    cout << "Enter a 3-character sub:"...

  • If I have to run another program from within my program, is system (anotherProgram) a good call to use? (Hint: env vari...

    If I have to run another program from within my program, is system (anotherProgram) a good call to use? (Hint: env variables; difference b/w exec or its variants and system call.) Google if you don't know what 'env variables' means things like current to, just like command line arguments @ run time. env variables are that the program has access path, name of shell etc, If I have to run another program from within my program, is system (anotherProgram) a...

  • I don't know how to run this code on visual studios and I don't understand why...

    I don't know how to run this code on visual studios and I don't understand why the answer is 211111118. Please explain! Thank you! CONSIDER THE FOLLOWING CODE: void Question() {       string x = "12";       mystery1(x);       string str1 = "21";       mystery2(str1);       string str2 = "11";       mystery2(str2);       string str3 = "31";       mystery2(str3);       string str4 = "91";       mystery2(str4);       string str5 = "81";       mystery1(str5);       x = x + str1 +...

  • I need help to calculate the sum of this, i just don't know how...... file_name =...

    I need help to calculate the sum of this, i just don't know how...... file_name = input("What is the value-probability file? ")     with open(file_name , "r") as final:         for numbers in final:             split_function = numbers.split()             num_one = float(split_function[0])             num_two = float(split_function[1])             final = num_one * num_two             final_line = final So when my code runs the output looks like this : What is the value-probability file? hw3_part2_test1.txt -0.567032 -17.630715000000002 3.194056 4.398823 13.990935 I need all these numbers now to add to...

  • I need help with my code when I run my code running the wrong thing like...

    I need help with my code when I run my code running the wrong thing like this After downSize() words.length=60003 wordCount=60003 vowelCount=206728 this is my code here import java.io.*; import java.util.*; public class Project02 {    static final int INITIAL_CAPACITY = 10;    public static void main (String[] args) throws Exception    {        // ALWAYS TEST FIRST TO VERIFY USER PUT REQUIRED INPUT FILE NAME ON THE COMMAND LINE        if (args.length < 1 )       ...

  • HI there I tried to run this code as an example given by my teacher, but...

    HI there I tried to run this code as an example given by my teacher, but when I copied and tried to run, then it ask to create BagInterface and ArrayBag class. Do i have to do something more previously in order to run this code. Can anyone help me her please? import java.util.Arrays; public class BagTraceExample {    public static void main(String[] args) {        BagInterface<String> animalBag = new ArrayBag();                          System.out.println(animalBag.isEmpty());...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT