Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Need help with chars/or's/if statements

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need help with chars/or's/if statements

    public class main {
    	public static void main(String[] args) {
    		start s=new start();
    		s.begin();
    	}
     
    }
    import java.util.Scanner;
    public class start {
    	converter c=new converter();
    	public void begin(){
    		boolean quit = false;
    		while (quit==false){
    			System.out.println("Welcome to Calvin's Pig Latin Translator.");
    			System.out.println("Press 1 to Start, 2 to Quit");
    			enter();
    			/*Scanner start=new Scanner(System.in); //when this runs, it always goes to the last else
    			String var=start.nextLine();
    			if(var.equals(1)){
    				enter();
    			}else{if(var.equals(2)){
    				quit=true;
    			}else{
    				System.out.println("Incorrect input. Please try again");
    			}
    			}*/
    		}
    	}
    	public void enter(){
    		System.out.println("Please enter the word you want to enter into Pig Latin");
    		Scanner word=new Scanner(System.in);
    		String input=word.nextLine();
    		c.word(input);
    	}
    }
    public class converter {
    	public void word(String wrd){
    		char letter='w';
    		String wooord=wrd;
    		if (!charKind(wrd.charAt(0))){
    			letter=wrd.charAt(0);
    			wooord=wrd.substring(1);
    		}
    		printer(letter, wooord);
    	}
    	public void printer(char cha, String wd){
    		System.out.println(wd+" "+cha+"ay. ");
    	}
    	boolean charKind(char ch){
    		boolean vowel=false;
    		if(ch==('a'|'e'|'i'|'o'|'u')){          //doesnt ever return true
    			vowel = true;
    		}
    		return vowel;
    	}
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Need help with chars/or's/if statements

    You forgot to ask you question. What do you need help with?

    If you are getting errors, please copy and paste here the full text of the error messages.

    Consider this:
    System.out.println("or'd chars=" + ('a'|'e'|'i'|'o'|'u')); //or'd chars=127
    The value of those letters ORd together is 127
    Last edited by Norm; February 4th, 2012 at 08:51 PM.

Similar Threads

  1. [SOLVED] NullPointerException when using methods to find matching chars in two arrays.
    By Javaisfrustrating in forum Exceptions
    Replies: 4
    Last Post: November 18th, 2011, 04:12 AM
  2. finding the amt of words and chars in a give file
    By mysticCHEEZE in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 3rd, 2011, 11:31 PM
  3. for loop with chars
    By dragon40226 in forum Loops & Control Statements
    Replies: 4
    Last Post: September 25th, 2011, 05:50 PM
  4. Reading input from console (greek chars)
    By lemmyz in forum File I/O & Other I/O Streams
    Replies: 10
    Last Post: August 16th, 2010, 05:37 AM
  5. Need help with While and For Statements
    By duckman in forum Loops & Control Statements
    Replies: 2
    Last Post: October 20th, 2009, 08:42 PM