Results 1 to 17 of 17

Thread: Question

  1. #1
    ayoood is offline Member
    Join Date
    May 2008
    Posts
    39
    Rep Power
    0

    Default 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

  2. #2
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    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?
    freedom exists in the world of ideas

  3. #3
    ayoood is offline Member
    Join Date
    May 2008
    Posts
    39
    Rep Power
    0

    Default

    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

  4. #4
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    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)....
    freedom exists in the world of ideas

  5. #5
    ayoood is offline Member
    Join Date
    May 2008
    Posts
    39
    Rep Power
    0

    Default

    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

  6. #6
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    If x1 is excellent and x2 low then y is almost good
    Java Code:
    if((x1==excellent)&&(x2<=low)){
         y="almost good";
    }
    freedom exists in the world of ideas

  7. #7
    ayoood is offline Member
    Join Date
    May 2008
    Posts
    39
    Rep Power
    0

    Default

    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

  8. #8
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    int excellent;
    int low;
    int poor;
    int verygood;
    int good;
    int nosignal;
    you may initialize first some values above.

    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

    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
    Last edited by sukatoa; 05-18-2008 at 04:11 PM.
    freedom exists in the world of ideas

  9. #9
    ayoood is offline Member
    Join Date
    May 2008
    Posts
    39
    Rep Power
    0

    Default

    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

  10. #10
    Eku
    Eku is offline Senior Member
    Join Date
    May 2008
    Location
    Makati, Philippines
    Posts
    234
    Rep Power
    7

    Default

    Try changing the data type of variable y to
    Java Code:
    String y=null;
    then out is:
    Java 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.

  11. #11
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    Not using Scanner,

    Java 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,
    Java 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
    Java 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....
    freedom exists in the world of ideas

  12. #12
    ayoood is offline Member
    Join Date
    May 2008
    Posts
    39
    Rep Power
    0

    Default

    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

  13. #13
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    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).
    freedom exists in the world of ideas

  14. #14
    ayoood is offline Member
    Join Date
    May 2008
    Posts
    39
    Rep Power
    0

    Default

    yes there are some of output i didn't get the right answer so what i should to do to get the right answer???

  15. #15
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  16. #16
    ayoood is offline Member
    Join Date
    May 2008
    Posts
    39
    Rep Power
    0

    Default

    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

  17. #17
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    try it,

    Java 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";
    }
    }
    }
    freedom exists in the world of ideas

Similar Threads

  1. Question mark colon operator question
    By orchid in forum Advanced Java
    Replies: 9
    Last Post: 12-19-2010, 08:49 AM
  2. a question
    By slytheman in forum Java Servlet
    Replies: 0
    Last Post: 03-12-2008, 04:11 AM
  3. Need help on this question
    By Deon in forum New To Java
    Replies: 3
    Last Post: 01-27-2008, 03:58 PM
  4. JNI question
    By javaplus in forum New To Java
    Replies: 0
    Last Post: 12-24-2007, 10:18 AM
  5. Need help with a question please
    By sonal in forum New To Java
    Replies: 1
    Last Post: 11-29-2007, 09:17 PM

Posting Permissions

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