variable answer1 might not have been initialized

variable answer1 might not have been initialized

import java .io.*; public class Test{ public static void main(String[] args) throws IOException{ BufferedReader steffi=new BufferedReader(new InputStreamReader(System.in)); String name; String answer1; int ctr1=0;

       System.out.println("Enter your name:");
       name=steffi.readLine();


       System.out.println("1.What is the name of the developer of java?");
       System.out.println("\tA. Steve Jobs");
       System.out.println("\tB. James Gosling");
       System.out.println("\tC. Bill Gates");
       System.out.println("\tD. None of these");
       System.out.print("Enter your answer:");
       if(answer1.equalsIgnoreCase("B"))
       {
        ctr1++;
       }


}

}

View Answers

September 17, 2012 at 11:07 AM

We have modified your code. Here it is:

import java .io.*;
public class Test{
    public static void main(String[] args) throws IOException{ 
        BufferedReader steffi=new BufferedReader(new InputStreamReader(System.in));
        String name; 
        String answer1=""; 
        int ctr1=0;

       System.out.println("Enter your name:");
       name=steffi.readLine();


       System.out.println("1.What is the name of the developer of java?");
       System.out.println("\tA. Steve Jobs");
       System.out.println("\tB. James Gosling");
       System.out.println("\tC. Bill Gates");
       System.out.println("\tD. None of these");
       System.out.print("Enter your answer:");
       answer1=steffi.readLine();
       if(answer1.equalsIgnoreCase("B"))
       {
        ctr1++;
       }

}

}

Ads









Related Tutorials/Questions & Answers:
variable answer1 might not have been initialized
variable answer1 might not have been initialized   import java .io...(System.in)); String name; String answer1; int...++; } } }   We have modified your code. Here it is: import java .io
Resources have been modified iPhone
Resources have been modified iPhone  Hi, My client is getting Resources have been modified error while installing AdHoc distribution on his iPhone. How to solve Resources have been modified iPhone error? Thanks   Hi
Advertisements
The app was not installed on iphone because its resources have been modified
The app was not installed on iphone because its resources have been modified  Hi, I am getting following error while my client is installing my... resources have been modified" What is the solution? Thanks   Hi, You have
How to find if you have been hit by Panda 4.0
How to find if you have been hit by Panda 4.0  Hi, This week Google Panda 4.0 is released. Now the question is how to find if your website have been... if your website have been hit by the Panda 4.0. Here are thinks you can do
ModuleNotFoundError: No module named 'mrsn-might'
have to install padas library. You can install mrsn-might python...ModuleNotFoundError: No module named 'mrsn-might'  Hi, My Python... 'mrsn-might' How to remove the ModuleNotFoundError: No module named 'mrsn
What is the purpose of declaring a variable as final?
What is the purpose of declaring a variable as final?   Hi, What is the purpose of declaring a variable as final? Thanks   Hi, In Java when we declare a final variable as a variable which has been initialized
Creating a Local Variable in JSP
consider a situation where we have to declare a variable as local, then we should...Creating a Local Variable in JSP          In jsp when we have to create a method
output variable
output variable  if i want to print output of three variables when i wrote the code e.g SYStem.out.PRINTln(answer + answer1 + answer 2) only output of answer is getting printed out? can you help
Local Variable and Instant Variable
Local Variable and Instant Variable  difference between Local Variable and Instant Variable   Difference between local variable and instance variable Instance variable is declared within a class but not within
if variable is null php
a variable, you might need to reset it too. In that case you can use... unset...if variable is null php  How to check if submitted variable is null in PHP? Thanks!   Check if Variable is NULL in PHP You can use isset
Protecting Your iPad Has Never Been Easier
. The amazing new features and light weight design have been largely responsible... convenient their lives have been or how their entertainment experiences have been...Protecting Your iPad Has Never Been Easier Since its release early in 2010
Duplicated Session Variables
;     We don't have any need to create a new session variable because it has been created by the JSP container for you... name. Consider we have declared a session variable true in jsp page <%@ page
Converting jsp variable to java variable
Converting jsp variable to java variable  Hi how to convert java script variable to java variable on same jsp page
Creating a Local Variable in JSP
Creating a Local Variable in JSP      In jsp when we have to create a method or variable we usually declare.... This works like a instance variable.  Now consider a situation where we have
Passing variable
Passing variable  How to pass variable to HTTP object in HTMl or PHP
What is instance variable in Java?
What is instance variable in Java?  Hi, What is instance variable in Java? What is the use of instance variable? Thanks   Hi, In Java programming classes are used as base of Object oriented programming. Any variable
ModuleNotFoundError: No module named 'variable'
ModuleNotFoundError: No module named 'variable'  Hi, My Python... 'variable' How to remove the ModuleNotFoundError: No module named 'variable' error? Thanks   Hi, In your python environment you have
Application Variable
Application Variable  I have multiple JSP's that are connected... the necessary data to establish a connection.. In every page I have to call... anyone show a simple sample code of storing the connection data in a variable so
environment variable
environment variable  what are the environment variable is need to run j2ee application in eclipse could you explain the details
final variable
final variable  Please give some easiest and understanding example program for final variable
environment variable
environment variable  what is environment variable in java?   Environment variables are used by the Operating System to pass configuration information to applications
Static Variable
Static Variable  What is the basic use of introducing static variable... that a certain object/variable is resident in memory and accessed each time an instance..., it means that the static variable is shared among all instances of the class
how to value of one variable pass in other variable in revetse order
how to value of one variable pass in other variable in revetse order  Like variable a=367 b must have valuev763
creating a global variable with php
creating a global variable with php  Is it possible to create a variable to declare as global in case of database connectivity?   Yes, if you want to have access of that variable anywhere in the program. See the example
Java Final Variable
Java Final Variable  I have some confusion --Final variable has single copy for each object so can we access final variable through class name,or it is necessary to create object for accessing final variable
Static variable in java
. These variable are initialized first before initializing of any instance...Static variable in java. Static is a keyword in java used to create static methods, variable inside a class and static class. Static variable
how to assign javascript variable value to a jsp variable
how to assign javascript variable value to a jsp variable  how to assign javascript variable value to a jsp variable
Instance variable in java
for instance variable. Instance variable have default values, for integer it is 0...Instance variable in java In this section you will learn about Instance variable in java. In java all variable must be declared before they are used
How to create variable in TensorFlow?
variable, you have to create the TensorFlow variable to use it with TensorFlow graph. Then tf.variable() method is used to create variable in TensorFlow...How to create variable in TensorFlow?  Hi, How to create variable
global variable in objective c
global variable in objective c  Declaring global variable in objective c
Java method final parameter
. In the example the radius parameter for calculating the area of circle have been set to final. This means double type radius is no more a variable.... And with this object following two tasks have been performed, first for providing the value

Ads