
05-17-2008, 10:17 AM
|
|
Member
|
|
Join Date: May 2008
Posts: 39
Rep Power: 0
|
|
Question
If i have this statement
For example:
If x1 equal to 12 and x2 equal to 5, then y is 3
So i use (if else) statement ???
In this programme i want to make this things when i press x1 some value and x2 some value that give me the result that i put it in the (if else ststement)
I don’t want anybody make the programme just i need to know the statement that i need it in this programme and how it done
Thank you for your helping
|
|

05-17-2008, 11:20 AM
|
 |
Senior Member
|
|
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 540
Rep Power: 3
|
|
|
I doubt about your statement....
Are you going to calculate first the two inputs?
and use it for comparison inside an if else statement?
or check the two inputs first? and try to search for a match pair?
could you post another detailed info about your algo?
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully
|
|

05-17-2008, 11:54 AM
|
|
Member
|
|
Join Date: May 2008
Posts: 39
Rep Power: 0
|
|
|
Im going to do project about wireless router
I will give x1 type of signal and x2 type of signal and y is the output .I have all the statement I have just to programmed it I need to know which statement that im going to use it that when I enter signal type for x1 and signal type of signal of x2 I get the right answer
|
|

05-17-2008, 12:32 PM
|
 |
Senior Member
|
|
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 540
Rep Power: 3
|
|
|
If you can predict 99.99% the output by calculating the 2 input signals,
then you can use switch statement on it,
if statement is also applicable but it adds more lines of code..(for me)....
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully
|
|

05-17-2008, 01:22 PM
|
|
Member
|
|
Join Date: May 2008
Posts: 39
Rep Power: 0
|
|
|
I know i tired you with me a ask a lot of question but this is the last question could you show me how does that written
If x1 is excellent and x2 low then y is almost good
Sorry about that
|
|

05-17-2008, 03:02 PM
|
 |
Senior Member
|
|
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 540
Rep Power: 3
|
|
|
Quote:
|
|
If x1 is excellent and x2 low then y is almost good
|
|
Code:
|
if((x1==excellent)&&(x2<=low)){
y="almost good";
} |
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully
|
|

05-18-2008, 04:23 PM
|
|
Member
|
|
Join Date: May 2008
Posts: 39
Rep Power: 0
|
|
|
import java.io.*;
public class Class1
{
public static void main (String [] args) throws java.io.IOException
{
int y;
int x1;
int x2;
int excellent;
int low;
int poor;
int verygood;
int good;
int nosignal;
System.out.println("Please enter x1");
System.out.println("Please enter x2");
if((x1==excellent)&&(x2<=low)){
y = "almost good" ;
}else if ((x1==excellent)&&(x2<=poor)){
y = "poor" ;
}else if ((x1==excellent)&&(x2<=nosignal)){
y = "no signal" ;
}else if ((x1==verygood)&&(x2<=low)){
y = " good" ;
}else if ((x1==verygood)&&(x2<=poor)){
y = "low" ;
}else if ((x1==verygood)&&(x2<=nosignal)){
y = "poor" ;
}else if ((x1==good)&&(x2<=low)){
y = "almost low" ;
}else if ((x1==good)&&(x2<=poor)){
y = "almost good" ;
}else if ((x1==good)&&(x2<=nosignal)) {
y = "poor" ;
} else{
y = "no sgnal" ;
}
System.out.println("your type of signal is:");
}
}
Sorry about that bro I wrote it by myself be there are some of error so could you see what is the wrong with my code
Im really sorry about that
|
|

05-18-2008, 05:07 PM
|
 |
Senior Member
|
|
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 540
Rep Power: 3
|
|
|
Quote:
|
int excellent;
int low;
int poor;
int verygood;
int good;
int nosignal;
|
you may initialize first some values above.
|
Quote:
|
System.out.println("Please enter x1");
System.out.println("Please enter x2");
|
You may read Scanner class for capturing inputs from keyboard... nextInt() method may fit your needs
|
Quote:
|
|
System.out.println("your type of signal is:");
|
How about concat(String s) method?
eg. System.out.println("Signal type is".concat(y));
or System.out.println("Signal type is"+y);
or System.out.printf("Signal type is %s\n",y); C type
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully
Last edited by sukatoa; 05-18-2008 at 05:11 PM.
|
|

05-19-2008, 10:16 PM
|
|
Member
|
|
Join Date: May 2008
Posts: 39
Rep Power: 0
|
|
|
i don’t know really what i do i try to solve the error but i couldn’t i read the file scanner class but i don’t know what i do with it I’m sorry about that i know it’s my wrong but i hope you to help me to overcome this problem i have only two days to submit the programme
|
|

05-20-2008, 03:40 AM
|
|
Senior Member
|
|
Join Date: May 2008
Location: Makati, Philippines
Posts: 234
Rep Power: 2
|
|
Try changing the data type of variable y to then out is:
|
Code:
|
System.out.println("your type of signal is: " + y); |
__________________
Mind only knows what lies near the heart, it alone sees the depth of the soul.
|
|

05-20-2008, 04:10 AM
|
 |
Senior Member
|
|
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 540
Rep Power: 3
|
|
Not using Scanner,
|
Code:
|
public class test{
public static void main(String args[]) throws Exception{
String y;
int x1;
int x2;
int excellent = 100;
int verygood = 75;
int good = 50;
int low = 20;
int poor = 10;
int nosignal = 0;
System.out.println("Please enter x1");
x1 = Integer.parseInt(String.valueOf((System.in.read(new byte[200]))));
System.out.println("Please enter x2");
x2 = Integer.parseInt(String.valueOf((System.in.read(new byte[200]))));
if((x1==excellent)&&(x2<=low)){
y = "almost good" ;
}else if ((x1==excellent)&&(x2<=poor)){
y = "poor" ;
}else if ((x1==excellent)&&(x2<=nosignal)){
y = "no signal" ;
}else if ((x1==verygood)&&(x2<=low)){
y = " good" ;
}else if ((x1==verygood)&&(x2<=poor)){
y = "low" ;
}else if ((x1==verygood)&&(x2<=nosignal)){
y = "poor" ;
}else if ((x1==good)&&(x2<=low)){
y = "almost low" ;
}else if ((x1==good)&&(x2<=poor)){
y = "almost good" ;
}else if ((x1==good)&&(x2<=nosignal)) {
y = "poor" ;
} else{
y = "no sgnal" ;
}
System.out.println("your type of signal is:" + y);
}
} |
Using Scanner,
|
Code:
|
public class test{
public static void main(String args[]) throws Exception{
String y;
int x1;
int x2;
int excellent = 100;
int verygood = 75;
int good = 50;
int low = 20;
int poor = 10;
int nosignal = 0;
System.out.println("Please enter x1");
x1 = Integer.parseInt(keyInput());
System.out.println("Please enter x2");
x2 = Integer.parseInt(keyInput());
if((x1==excellent)&&(x2<=low)){
y = "almost good" ;
}else if ((x1==excellent)&&(x2<=poor)){
y = "poor" ;
}else if ((x1==excellent)&&(x2<=nosignal)){
y = "no signal" ;
}else if ((x1==verygood)&&(x2<=low)){
y = " good" ;
}else if ((x1==verygood)&&(x2<=poor)){
y = "low" ;
}else if ((x1==verygood)&&(x2<=nosignal)){
y = "poor" ;
}else if ((x1==good)&&(x2<=low)){
y = "almost low" ;
}else if ((x1==good)&&(x2<=poor)){
y = "almost good" ;
}else if ((x1==good)&&(x2<=nosignal)) {
y = "poor" ;
} else{
y = "no sgnal" ;
}
System.out.println("your type of signal is:" + y);
}
private static final String keyInput(){
return new java.util.Scanner(System.in).nextLine();
}
} |
Using Buffered IO
|
Code:
|
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class test{
public static void main(String args[]) throws Exception{
String y;
int x1;
int x2;
int excellent = 100;
int verygood = 75;
int good = 50;
int low = 20;
int poor = 10;
int nosignal = 0;
System.out.println("Please enter x1");
x1 = Integer.parseInt(String.valueOf((keyInput())));
System.out.println("Please enter x2");
x2 = Integer.parseInt(String.valueOf(keyInput()));
if((x1==excellent)&&(x2<=low)){
y = "almost good" ;
}else if ((x1==excellent)&&(x2<=poor)){
y = "poor" ;
}else if ((x1==excellent)&&(x2<=nosignal)){
y = "no signal" ;
}else if ((x1==verygood)&&(x2<=low)){
y = " good" ;
}else if ((x1==verygood)&&(x2<=poor)){
y = "low" ;
}else if ((x1==verygood)&&(x2<=nosignal)){
y = "poor" ;
}else if ((x1==good)&&(x2<=low)){
y = "almost low" ;
}else if ((x1==good)&&(x2<=poor)){
y = "almost good" ;
}else if ((x1==good)&&(x2<=nosignal)) {
y = "poor" ;
} else{
y = "no sgnal" ;
}
System.out.println("your type of signal is:" + y);
}
private static final String keyInput(){
try{
return new BufferedReader(new InputStreamReader(System.in)).readLine();
}catch(Exception e){
e.printStackTrace();
return "0";
}
}
} |
Try to test it, have some experiments on it....
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully
|
|

05-20-2008, 12:08 PM
|
|
Member
|
|
Join Date: May 2008
Posts: 39
Rep Power: 0
|
|
|
I am unable to express thank very much the word and a few in your right Thank You deserve more than this word all the programmes compile with me , you're really creative
Thank you very much again
|
|

05-21-2008, 06:19 AM
|
 |
Senior Member
|
|
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 540
Rep Power: 3
|
|
|
You're welcome,
Eku's reply is the very important part, in post #7, i think you've stuck because you couldn't see any output....
next time, if you want to have an experiment, you may plan first on how you will display the output....
(that's the only evident you can use to decide whether it's correct or wrong).
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully
|
|

05-21-2008, 11:22 AM
|
|
Member
|
|
Join Date: May 2008
Posts: 39
Rep Power: 0
|
|
|
yes there are some of output i didn't get the right answer so what i should to do to get the right answer???
|
|

05-21-2008, 11:34 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 7,513
Rep Power: 11
|
|
|
What output you are expecting here.
|
|

05-21-2008, 02:58 PM
|
|
Member
|
|
Join Date: May 2008
Posts: 39
Rep Power: 0
|
|
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class test{
public static void main(String args[]) throws Exception{
String y=null;
int x1;
int x2;
int excellent = 100;
int verygood = 75;
int good = 50;
int low = 20;
int poor = 10;
int nosignal = 0;
System.out.println("Please enter x1");
x1 = Integer.parseInt(String.valueOf((keyInput())));
System.out.println("Please enter x2");
x2 = Integer.parseInt(String.valueOf(keyInput()));
if((x1==excellent)&&(x2<=low)){
y = "almost good" ;
}else if ((x1==excellent)&&(x2<=poor)){
y = "poor" ;
}else if ((x1==excellent)&&(x2<=nosignal)){
y = "no signal" ;
}else if ((x1==verygood)&&(x2<=low)){
y = " good" ;
}else if ((x1==verygood)&&(x2<=poor)){
y = "low" ;
}else if ((x1==verygood)&&(x2<=nosignal)){
y = "poor" ;
}else if ((x1==good)&&(x2<=low)){
y = "almost low" ;
}else if ((x1==good)&&(x2<=poor)){
y = "almost good" ;
}else if ((x1==good)&&(x2<=nosignal)) {
y = "poor" ;
} else{
y = "no sgnal" ;
}
System.out.println("your type of signal is:" + y);
}
private static final String keyInput(){
try{
return new BufferedReader(new InputStreamReader(System.in)).readLine();
}catch(Exception e){
e.printStackTrace();
return "0";
}
}
}
Try to test it, have s
|
|

05-21-2008, 03:23 PM
|
 |
Senior Member
|
|
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 540
Rep Power: 3
|
|
try it,
|
Code:
|
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class test{
public static void main(String args[]) throws Exception{
String y=null;
int x1;
int x2;
int excellent = 100;
int verygood = 75;
int good = 50;
int low = 20;
int poor = 10;
int nosignal = 0;
System.out.println("Please enter x1");
x1 = Integer.parseInt(String.valueOf((keyInput())));
System.out.println("Please enter x2");
x2 = Integer.parseInt(String.valueOf(keyInput()));
if((x1==excellent)&&(x2>poor)){
y = "almost good" ;
}else if ((x1==excellent)&&(x2==poor)&&(x2>nosignal)){
y = "poor" ;
}else if ((x1==excellent)&&(x2<=nosignal)){
y = "no signal" ;
}else if ((x1==verygood)&&(x2>poor)){
y = " good" ;
}else if ((x1==verygood)&&(x2==poor)&&(x2>nosignal)){
y = "low" ;
}else if ((x1==verygood)&&(x2<=nosignal)){
y = "poor" ;
}else if ((x1==good)&&(x2>poor)){
y = "almost low" ;
}else if ((x1==good)&&(x2==poor)&&(x2>nosignal)){
y = "almost good" ;
}else if ((x1==good)&&(x2<=nosignal)) {
y = "poor" ;
} else{
y = "no sgnal" ;
}
System.out.println("your type of signal is:" + y);
}
private static final String keyInput(){
try{
return new BufferedReader(new InputStreamReader(System.in)).readLine();
}catch(Exception e){
e.printStackTrace();
return "0";
}
}
} |
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT +2. The time now is 10:11 PM.
|
|