Thread: Question
View Single Post
  #11 (permalink)  
Old 05-20-2008, 04:10 AM
sukatoa's Avatar
sukatoa sukatoa is offline
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 526
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
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
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Reply With Quote