# Height and weight may not have been intialized?

Page 1 of 1

## 12 Replies - 437 Views - Last Post: 03 February 2018 - 05:39 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=409065&amp;s=f846a11acbd2e0b2f4676809f6ce7370&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 tlclayton1

Reputation: 0
• Posts: 22
• Joined: 13-January 18

# Height and weight may not have been intialized?

Posted 02 February 2018 - 03:35 AM

```public class RudeQuestions {
public static void main( String[] args ) {
String name;
int age;
double weight, income;
double height, drawer;

Scanner keyboard = new Scanner(System.in);

System.out.print( "Hello. What is your name? ");
name = keyboard.next();

System.out.print( "Hi, " + name+ "! How old are you? ");
age = keyboard.nextInt();

System.out.println( "So you're " + age + ", eh? That's not very old. " );
System.out.print( "How much do you weigh, " + "? ");
weight = keyboard.nextDouble();

System.out.println ( weight + "! Better keep that quiet!!" );
System.out.print("Finally, what's your income, " + name + "?" );
income = keyboard.nextDouble();

System.out.print( "Hopefully, that is " + income+ "per hour" );
System.out.println( " and not per year!" );
System.out.print( "Well, thanks for answering my rude questions, " );
System.out.println( name + ".");
/*
The program doesn't blow up entering a integer for a double because it's a number.
The program doesn't blow up entering a numeric value for a string because strings encompass damn near everything.
When I entered a string /words for a integer or double it blew up and I dont know why considering the comment above.
*/
System.out.println( name + " ! I have one more thing to ask you!!" );
height = keyboard.nextDouble();

System.out.print ("What is your " + drawer  + "ha ha" );
drawer  = keyboard.nextDouble();

}
}

```

The code will not compile. The error message sais height and weight may not have been initialized. I understand that height/weight must = something but if I remove variables height and weight the program will compile even though I didn't initialize weight and income.

This post has been edited by baavgai: 02 February 2018 - 03:43 AM
Reason for edit:: tagged

Is This A Good Question/Topic? 0

## Replies To: Height and weight may not have been intialized?

### #2 g00se

• D.I.C Lover

Reputation: 3540
• Posts: 16,130
• Joined: 20-September 08

## Re: Height and weight may not have been intialized?

Posted 02 February 2018 - 03:39 AM

Please use code tags as you were asked. andrewsw's instructions will show you how to use code-tags. It isn't difficult.
EACH JAVA FILE should have its own code tags

### #3 GazinAtCode

Reputation: 33
• Posts: 121
• Joined: 26-September 16

## Re: Height and weight may not have been intialized?

Posted 02 February 2018 - 04:13 AM

I guess you mean height and drawer. The problem is that you're trying to use them in the print method before they are initialized (lines 35-36 and 38-39). That is not the case with the rest of the variables.

This post has been edited by GazinAtCode: 02 February 2018 - 04:15 AM

### #4 g00se

• D.I.C Lover

Reputation: 3540
• Posts: 16,130
• Joined: 20-September 08

## Re: Height and weight may not have been intialized?

Posted 02 February 2018 - 04:53 AM

You need to look at those again. Even if you had initialized them correctly, the way you're using them is wrong - it doesn't make sense

### #5 tlclayton1

Reputation: 0
• Posts: 22
• Joined: 13-January 18

## Re: Height and weight may not have been intialized?

Posted 02 February 2018 - 11:32 AM

How do I use height and drawer in code so it compiles? How do you mean initialize?

### #6 tlclayton1

Reputation: 0
• Posts: 22
• Joined: 13-January 18

## Re: Height and weight may not have been intialized?

Posted 02 February 2018 - 11:59 AM

[quote name='tlclayton1' date='02 February 2018 - 11:32 AM' timestamp='1517596357' post='2352873']
Okay I initialized height and drawer and it compiled but it made no sense. The datatype used for height and drawer was double. Below was the result of my compiling.

```import java.util.Scanner;

public class RudeQuestions {
public static void main( String[] args ) {
String name;
int age;
double weight, income;
string height, drawer;
height = height;
drawer = drawer;

Scanner keyboard = new Scanner(System.in);

System.out.print( "Hello. What is your name? ");
name = keyboard.next();

System.out.print( "Hi, " + name+ "! How old are you? ");
age = keyboard.nextInt();

System.out.println( "So you're " + age + ", eh? That's not very old. " );
System.out.print( "How much do you weigh, " + "? ");
weight = keyboard.nextDouble();

System.out.println ( weight + "! Better keep that quiet!!" );
System.out.print("Finally, what's your income, " + name + "?" );
income = keyboard.nextDouble();

System.out.print( "Hopefully, that is " + income+ "per hour" );
System.out.println( " and not per year!" );
System.out.print( "Well, thanks for answering my rude questions, " );
System.out.println( name + ".");
/*
The program doesn't blow up entering a integer for a double because it's a number.
The program doesn't blow up entering a numeric value for a string because strings encompass damn near everything.
When I entered a string /words for a integer or double it blew up and I dont know why considering the comment above.
*/
System.out.println( name + " ! I have one more thing to ask you!!" );
height = keyboard.nextDouble();

System.out.print ("What is your " + drawer  + "ha ha" );
drawer  = keyboard.nextDouble();
```

I attempted to use the string datatype and it wouldn't compile. What would you guys have done to make this make sense?

Thank you,
T

[quote name='tlclayton1' date='02 February 2018 - 11:55 AM' timestamp='1517597751' post='2352879']

tlclayton1, on 02 February 2018 - 11:32 AM, said:

Okay I initialized height and drawer and it compiled but it made no sense. The datatype used for height and drawer was double. Below was the result of my compiling.

```import java.util.Scanner;

public class RudeQuestions {
public static void main( String[] args ) {
String name;
int age;
double weight, income;
string height, drawer;
height = 54;
drawer = 64;

Scanner keyboard = new Scanner(System.in);

System.out.print( "Hello. What is your name? ");
name = keyboard.next();

System.out.print( "Hi, " + name+ "! How old are you? ");
age = keyboard.nextInt();

System.out.println( "So you're " + age + ", eh? That's not very old. " );
System.out.print( "How much do you weigh, " + "? ");
weight = keyboard.nextDouble();

System.out.println ( weight + "! Better keep that quiet!!" );
System.out.print("Finally, what's your income, " + name + "?" );
income = keyboard.nextDouble();

System.out.print( "Hopefully, that is " + income+ "per hour" );
System.out.println( " and not per year!" );
System.out.print( "Well, thanks for answering my rude questions, " );
System.out.println( name + ".");
/*
The program doesn't blow up entering a integer for a double because it's a number.
The program doesn't blow up entering a numeric value for a string because strings encompass damn near everything.
When I entered a string /words for a integer or double it blew up and I dont know why considering the comment above.
*/
System.out.println( name + " ! I have one more thing to ask you!!" );
height = keyboard.nextDouble();

System.out.print ("What is your " + drawer  + "ha ha" );
drawer  = keyboard.nextDouble();
```

Hello. What is your name? T
Hi, T! How old are you? 41
So you're 41, eh? That's not very old.
How much do you weigh, ? 168
168.0! Better keep that quiet!!
Hopefully, that is 120000.0per hour and not per year!
Well, thanks for answering my rude questions, T.
T ! I have one more thing to ask you!!
PS C:\Users\T\Documents\javahard>

I attempted to use the string datatype and it wouldn't compile. What would you guys have done to make this make sense?

Thank you,
T

### #7 g00se

• D.I.C Lover

Reputation: 3540
• Posts: 16,130
• Joined: 20-September 08

## Re: Height and weight may not have been intialized?

Posted 02 February 2018 - 11:59 AM

The concatenation of the variable with the prompt makes no sense - don't do it. What does 'drawer' mean?

### #8 NormR

• D.I.C Lover

Reputation: 691
• Posts: 5,267
• Joined: 25-December 13

## Re: Height and weight may not have been intialized?

Posted 02 February 2018 - 12:43 PM

Quote

it wouldn't compile

Please copy the full text of the error message and paste it here. It has important info about the error.

### #9 tlclayton1

Reputation: 0
• Posts: 22
• Joined: 13-January 18

## Re: Height and weight may not have been intialized?

Posted 02 February 2018 - 04:41 PM

g00se, on 02 February 2018 - 11:59 AM, said:

The concatenation of the variable with the prompt makes no sense - don't do it. What does 'drawer' mean?

Drawer is underwear size

### #10 g00se

• D.I.C Lover

Reputation: 3540
• Posts: 16,130
• Joined: 20-September 08

## Re: Height and weight may not have been intialized?

Posted 03 February 2018 - 05:49 AM

OK. Well the comments so far have mentioned what the errors are. Read those and ensure that the last of the two prompts follow the approach of the earlier ones

### #11 tlclayton1

Reputation: 0
• Posts: 22
• Joined: 13-January 18

## Re: Height and weight may not have been intialized?

Posted 03 February 2018 - 04:54 PM

I just want to the program to run by saying may I ask what is your height? and what is your drawer?

I've tried using String data types and double. In both instances i've been told to initialize them. If I initialize them like so
height = whatever/ drawer = whatever the words height and weight won't be in the sentence.

### #12 tlclayton1

Reputation: 0
• Posts: 22
• Joined: 13-January 18

## Re: Height and weight may not have been intialized?

Posted 03 February 2018 - 05:19 PM

I figured it out finally. All I had to do was use the String variable and put quotation marks around the words height and weight making it officially a string.
```import java.util.Scanner;

public class RudeQuestions {
public static void main( String[] args ) {
String name;
int age;
double weight, income;
String height, drawer;
height = "height";
drawer = "drawer";

Scanner keyboard = new Scanner(System.in);

System.out.print( "Hello. What is your name? ");
name = keyboard.next();

System.out.print( "Hi, " + name+ "! How old are you? ");
age = keyboard.nextInt();

System.out.println( "So you're " + age + ", eh? That's not very old. " );
System.out.print( "How much do you weigh, " + "? ");
weight = keyboard.nextDouble();

System.out.println ( weight + "! Better keep that quiet!!" );
System.out.print("Finally, what's your income, " + name + "?" );
income = keyboard.nextDouble();

System.out.print( "Hopefully, that is " + income+ "per hour" );
System.out.println( " and not per year!" );
System.out.print( "Well, thanks for answering my rude questions, " );
System.out.println( name + ".");
/*
The program doesn't blow up entering a integer for a double because it's a number.
The program doesn't blow up entering a numeric value for a string because strings encompass damn near everything.
When I entered a string /words for a integer or double it blew up and I dont know why considering the comment above.
*/
System.out.println( name + " ! I have one more thing to ask you!!" );
System.out.print( "May, I ask what is your " + "height" + "?" );
height = keyboard.next();

System.out.print ("What is your " + "drawer" + "?" );
drawer  = keyboard.next();
```

}
}

Output

2 errors
PS C:\Users\T\Documents\javahard> javac RudeQuestions.java
PS C:\Users\T\Documents\javahard> java RudeQuestions
Hello. What is your name? T
Hi, T! How old are you? 41
So you're 41, eh? That's not very old.
How much do you weigh, ? 158
158.0! Better keep that quiet!!
Finally, what's your income, T? 100000
Hopefully, that is 100000.0per hour and not per year!
Well, thanks for answering my rude questions, T.
T ! I have one more thing to ask you!!
PS C:\Users\T\Documents\javahard>

### #13 NormR

• D.I.C Lover

Reputation: 691
• Posts: 5,267
• Joined: 25-December 13

## Re: Height and weight may not have been intialized?

Posted 03 February 2018 - 05:39 PM

```"What is your " + "drawer" + "?"
vs