# Thread: can someone help me to run this program caus' im havin hardtime to run this!

1. Member
Join Date
Aug 2013
Posts
5
Rep Power
0

## 3rd looping statement problem

import java.io.*;
import java.lang.*;

public class Conversion {

public static void main(String args[])throws IOException

String a, x, y;
int select = 0, select2 = 0;

while(select < 3)
{
System.out.println("You want to proceed? [y/n]? ");

if(a.equals("y"))
{
while(select2 < 3)
{
select2 = 0;

System.out.println("List of Conversions:");
System.out.println("");
System.out.println("Select[a]To Convert Decimal to Binary.");
System.out.println("Select[b]To Convert Decimal to Octal.");
System.out.println("Choose wisely!: ");
if(x.equals("a"))
{ select2 = 1;
if(select2 == 1)
{
System.out.println("Enter a decimal number!:");
int value = Integer.parseInt(deci);
String strs = Integer.toString(value,2);
System.out.println("decimal:" + strs);
System.out.println("do you want to go back? [y/n]?");
if(y.equals("y"))
{
select2 = 0;
}
else if(y.equals("n"))
{
select2 = 2;
select = 1;
}

}
}

else if(x.equals("b"))
{
System.out.println("Enter a decimal number:");
int value = Integer.parseInt(deci);
String str = Integer.toString(value,8);
System.out.println("octal:" + str);
System.out.println("do you want to go back? [y/n]?");
if(y.equals("y"))
{
select2 = 0;
}
else if(y.equals("n"))
{
select2 = 2;
select = 1;
}
}
}

}
else if(x.equals("c"))
{
System.out.println("Enter a decimal number:");
int value = Integer.parseInt(deci);
String str = Integer.toString(value,16);
System.out.println("hexa:" + str);
System.out.println("do you want to go back? [y/n]?");
if(y.equals("y"))
{
select2 = 0;
}
else if(y.equals("n"))
{
select2 = 2;
select = 1;
{
}
}

else if(a.equals("n"))
{
select = 1;
}

if(select ==1)
{
System.out.println("Thanks");
}
}

}
}
}
having hard time to fix the 3rd looping statement!
Last edited by blut.vene; 08-26-2013 at 07:44 AM.

2. ## Re: can someone help me to run this program caus' im havin hardtime to run this!

It will not even compile without initialization of "x" cz in the start of the loop you are taking input to "a" . If "(a.equals("y"))" fails then how this " (x.equals("b")) " expression will execute as you haven't initialized "x".One more thing, edit your post and place your code between tags and go through forum rules ...

3. ## Re: can someone help me to run this program caus' im havin hardtime to run this!

you are having problem with scope of while loops,just cut
Java Code:
``` if(x.equals("c"))
{
System.out.println("Enter a decimal number:");
int value = Integer.parseInt(deci);
String str = Integer.toString(value,16);
System.out.println("hexa:" + str);
System.out.println("do you want to go back? [y/n]?");
if(y.equals("y"))
{
select2 = 0;
}
else if(y.equals("n"))
{
select2 = 2;
select = 1;
{
}
}

else if(a.equals("n"))
{
select = 1;
}

if(select ==1)
{
System.out.println("Thanks");
}
}```
part of your code and copy it to two braces up and in last else; write code for (a.equals("n")) .. and you are done ...
Last edited by allaudin; 08-26-2013 at 06:12 AM.

4. ## Re: can someone help me to run this program caus' im havin hardtime to run this!

Java Code:
```if(x.equals("a")) {
select2 = 1;
if(select2 == 1) {```
When will the inner if statement ever be false? Seems pointless to me.

5. ## Re: can someone help me to run this program caus' im havin hardtime to run this!

Originally Posted by Junky
Java Code:
```if(x.equals("a")) {
select2 = 1;
if(select2 == 1) {```
When will the inner if statement ever be false? Seems pointless to me.
exactly I was thinking the same .. I am even unable to understand the purpose of these select variables as the condition for both while loops will always true .
while(select < 3)
{
System.out.println("You want to proceed? [y/n]? ");

if(a.equals("y"))
{
while(select2 < 3)
{
Last edited by allaudin; 08-26-2013 at 06:07 AM.

6. ## Re: can someone help me to run this program caus' im havin hardtime to run this!

More ugly code: why create a new BufferedReader all the time. Just create one and use it to gather ALL user input. Just a waste of resources if you create more than one.

7. ## Re: can someone help me to run this program caus' im havin hardtime to run this!

yup ... it seems he is a sheer beginner

8. ## Re: can someone help me to run this program caus' im havin hardtime to run this!

Originally Posted by blut.vene
can someone help me to run this program caus' im havin hardtime to run this!
Please go through the Forum Rules with special reference to the third paragrpah. Then go through the http://www.java-forums.org/forum-gui...w-members.html and BB Code List - Java Programming Forum - Learn Java Programming and edit your post accordingly.

db

9. Member
Join Date
Aug 2013
Posts
5
Rep Power
0

## Re: can someone help me to run this program caus' im havin hardtime to run this!

Output:
[a] for Decimal to Binary
[b] for Decimal to Octal
Choose one:

========================================
example A:
i.
[a] for Decimal to Binary
[b] for Decimal to Octal
Choose one: a

ii.
Input value to convert: 100
Decimal is: 1100100

example B:
i.
[a] for Decimal to Binary
[b] for Decimal to Octal
Choose one: b

ii.
Input value to convert: 100
Octal is: 144

example C:
i.
[a] for Decimal to Binary
[b] for Decimal to Octal
Choose one: c

ii.
Input value to convert: 255
Hexa is: FF
this should be the output of that program,
and im havin trouble with the third looping statement.
Yep sirs im just a newbie at programming

10. Member
Join Date
Aug 2013
Posts
5
Rep Power
0

## Re: can someone help me to run this program caus' im havin hardtime to run this!

i'm sorry for the inconvinience btw how to change the thread name so that I can stick with the rule.

11. ## Re: can someone help me to run this program caus' im havin hardtime to run this!

I think you should have separate functions for Binary, Octal and Hexadecimal ... and call these methods from main ...

12. ## Re: can someone help me to run this program caus' im havin hardtime to run this!

Originally Posted by blut.vene
i'm sorry for the inconvinience btw how to change the thread name so that I can stick with the rule.
Let it be for this thread, but please keep the rules in mind when you have another question.

db

13. Member
Join Date
Aug 2013
Posts
5
Rep Power
0

## Re: can someone help me to run this program caus' im havin hardtime to run this!

How to do that mr allaudin im really confused and having hard time.

15. Member
Join Date
Aug 2013
Posts
5
Rep Power
0

## Re: can someone help me to run this program caus' im havin hardtime to run this!

thanks mr allaudin!

here it goes
import java.io.*;
import java.lang.*;

public class Conversion {

public static void main(String args[])throws IOException

String a, x, y;
int select = 0, select2 = 0;

while(select < 1)
{
System.out.println("You want to proceed? [y/n]? ");

if(a.equals("y"))
{ //2 < 2
while(select2 < 2)
{
select2 = 0;
System.out.println("CONVERSION");
System.out.println("");
System.out.println("List of Conversions:");
System.out.println("");
System.out.println("[a] Decimal to Binary");
System.out.println("[b] Decimal to Octal");
System.out.println("Choose one: ");
if(x.equals("a"))
{ select2 = 1;
if(select2 == 1)
{

System.out.println("Enter the decimal number:");
int value = Integer.parseInt(deci);
String str = Integer.toString(value,8);
System.out.println("octal:=" + str);
System.out.println("do you want to go back? [y/n]?");
if(y.equals("y"))
{
select2 = 0;
}
else if(y.equals("n"))
{
select2 = 2;
select = 1;
}

}//terminates IF for select2 variable
}//terminates IF for x variable

else if(x.equals("b"))
{
System.out.println("Enter the decimal number:");
int value = Integer.parseInt(deci);
String str = Integer.toString(value,8);
System.out.println("octal:=" + str);
System.out.println("do you want to go back? [y/n]?");
if(y.equals("y"))
{
select2 = 0;
}
else if(y.equals("n"))
{
select2 = 2;
select = 1;
}
}

else if(x.equals("c"))
{ select2 = 3;
if(select2 == 3)
{
System.out.println("Enter the decimal number:");
int value = Integer.parseInt(deci);
String str = Integer.toString(value,16);
System.out.println("octal:=" + str);
System.out.println("do you want to go back? [y/n]?");

switch (y) {
case "y":
select2 = 0;
break;
case "n":
select2 = 2;
select = 1;
if(y.equals("n"))
{
select = 1;
}if(select ==1)
{
System.out.println("Thanks");
}
break;
}
}
}
}
}
}
}
}

16. ## Re: can someone help me to run this program caus' im havin hardtime to run this!

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•