import java.io.*;
class Dictionary
{
	public static void main(String[] args)
	{
		Console console=System.console();
                System.out.println("Please enter the next number");  
                String input;
                input=console.readLine();
                 
            
             String[] Hebrew={"ehad", "shnaiim","shalosh","arba","hamesh","shesh","sheva","shmone","tesha","eser"};
    
                  
             
             String[] English={"one", "two","three","four","five","six","seven","eight","nine","ten"};     

            
          
           
                 

            for(int x=0;x<Hebrew.length;x++)
            {   if(input.equals(Hebrew[x]))
                {
                System.out.println(English[x]);
                }  

                         
                  }       
	     } 
                    
                   
                          {
                         while(!input.equals("enough") ) //i want to make a condition that if the program doesnt find a number it would do this. but it wont allow me too
                         {
       
                         System.out.println("Illegal word, please enter another word");
                          input=console.readLine();
                          } 
                       
                       
                         

                 
                    
                
            
          }


}

I am trying to build a mini translator 1-10 from hebrew to english

now i find it difficult to tell the dictionary to say that if there is no such word in the dictionary, it should write that there is no such word and ask again until the word is correct or it was typed "enough"

NO PROBLEM my dear friend you can make a boolean variable called found initialized to false then if the word was found then change it to be true else sout that the word u r searchin is not found .. try it and tell me

What does this comment mean?

NormR1 - i think it means that N_O_ does not understand how to make it work.

N_O_ the reply above will get you a condition, but you do not even need to do that. Just initialize the output string with the did not find message, assign in the loop then print after.

Harry

NewOrder how about trying this code which translates one to ten from Hebrew to English and vice versa, Please do not accuse me of doing your homework, could not resist but tryout the code.

//import java.io.*;
import java.util.Scanner;//assist to read user input from console
class translator
{
	public static void main(String[] args)
	{
	 String[] Hebrew={"ehad", "shnaiim","shalosh","arba","hamesh","shesh","sheva","shmone","tesha","eser"};
         String[] English={"one", "two","three","four","five","six","seven","eight","nine","ten"};     

		String strInput;
		int counter, intInput;
		boolean InputResult, validInput = false;
		boolean engFound, hebFound;
		int engLoc=0, hebLoc=0;
		do	
		{
			Scanner scanner = new Scanner(System.in);
			System.out.println("Please enter word:");
			strInput = scanner.nextLine();
			engFound = false; hebFound=false;
			//search in hebrew array
			for(int c = 0;c<=Hebrew.length-1;c++)
			{
				if (strInput.toUpperCase().equals(Hebrew[c].toUpperCase()))
				{
					hebFound = true;
					hebLoc = c;
				}
			}
			//search in english array
			for(int c = 0;c<=English.length-1;c++)
			{
				if (strInput.toUpperCase().equals(English[c].toUpperCase()))
				{
					engFound=true;
					engLoc = c;
				}
			}			

		}
		while ((strInput!= "enough") && (engFound==false) && (hebFound==false) );
		if (engFound==true)
			System.out.println(strInput + " in hebrew is " + Hebrew[engLoc] );
		if (hebFound==true)
			System.out.println(strInput + " in english is " + English[hebLoc] );
	}

}

Edited 6 Years Ago by mnmw: n/a

thanks for the code, i think it is longer than necessary,

i need also to adapt it, ..


i need to add a condition that if it is being written enough

then the sequence should stop

import java.util.Scanner;//assist to read user input from console

i dont know what the hell that is , so i cant include it in my code

The condition is one of the the loop condition terminators:

while ((strInput!= "enough") && (engFound==false) && (hebFound==false) )

import java.util.Scanner is java package (header file) that will facilitate use these two statements:

Scanner scanner = new Scanner(System.in);
System.out.println("Please enter word:");
strInput = scanner.nextLine();

However you can stick to the java.io* and Console which you are used to.

i am going to modify your code a bit, this evening,

Scanner scanner = new Scanner(System.in);


i dont know what it is , and therefore, i will need to find an alternative solution


thank you for your help and i will post my newly revised code, this evening , hopefully

import java.io.*;
class Dictionary
{
	public static void main(String[] args)
	{
		Console console=System.console();
                System.out.println("Please enter the next number");  
                String input;
                input=console.readLine();
                boolean engFound=true;
                String enough=("enough");

             String[] Hebrew={"ehad", "shnaiim","shalosh","arba","hamesh","shesh","sheva","shmone","tesha","eser"};
    
                  
             
             String[] English={"one", "two","three","four","five","six","seven","eight","nine","ten"};     

                     
                           
                     
                        for(int x=0;x<Hebrew.length;x++)
                        {
                            if(input.equals(Hebrew[x]))
                             System.out.println(input + " in hebrew is " + English[x]);
                             engFound=true;
                            
                         }


                         while(!engFound || input.equals("enough"))
                         {
                         System.out.println("Illegal Word,Please enter the keyword again");
                         input=console.readLine();
                          }
                        
                    
          

            }
   }

i looked at your code, and i think it is too complex, and doesnt respond to the word "enough"


i revised my code . however, i struggle to connect while and if..

when it finishes going through the numbers, it doesnt even go to while

Have you thought of trying to design the logic for your program using something like a flowchart?
Most programmers work out the logic of a problem BEFORE trying to write code.

i dont know know what a flowchart is.

i dont need to rewrite it. it works half way, the other halfway doesnt work..

i need to connect both loops somehow, so far coming with some variable and putting in both loops doesnt work

You do need to DESIGN it! Flowcharting is a tool to help you design a program.
Without the logic flow worked out before you start coding, you end up with a mess.
QED

i dont understand , why in this code

when you declare the

the boolean variable at teh start , it initializes and mine doesnt?

import java.io.*;
class ValidHex
{
	public static void main(String[] args)
	{
		Console console=System.console();
		String hex;
		boolean valid;// this one is initialized. but i have my variable writen in the same way and it doesnt initialize
	     do{
		System.out.println("Please enter a valid hexadecimal number");
		
		hex=console.readLine();
		if(hex.length()==0)
			valid=false;
		else
			valid=true;

		for(int index=0;index<hex.length() && valid; index++)
		{
			switch(hex.charAt(index))
			{
				case '0': case '1': case '2': case '3': case '4': case '5': case '6':
				case '7': case '8': case '9': case 'a': case 'b': case 'c': case 'd':
				case 'e': case 'f': case 'A': case 'B': case 'C': case 'D': case 'E':
				case 'F':
					break;
				default:
					valid=false;
					break;
			}
		}
		if(!valid)
			System.out.println("Illegal number");
	      }while(!valid);

	}



}

boolean valid;// this one is initialized. but i have my variable writen in the same way and it doesnt initialize

Where is yours defined? Inside a method or out?

Edited 6 Years Ago by NormR1: n/a

This article has been dead for over six months. Start a new discussion instead.