tong1 22 Posting Whiz

jemz, the program you are goint to make is working in this way:
The client has to input 4 words,
Then the program checks each individual word to see if it is palindrom.
If so, your outpu seems OK.
Am I right?

tong1 22 Posting Whiz

In this case the program checks the sentence to see if its series of words are palindrome.
The sentence in terms of words:
jemz loves JAVA loves jemz
is palindrome since you see the symmetrical pattern:
jemz to jemz
loves to loves
and
the JAVA to itself JAVA.
The following sentence is not a palindrome: zemz loves JAVA loves aaaa since it is not symmetric.
This is the rule to compare the series of words to see if they are palindrome or not.
Of course, you may modify the rule, e.g. ignoring the the difference in upper/lower case , ignoring interpunction....

tong1 22 Posting Whiz

After the program has receive 5 words inputed, the i became 5. The the program goes to line 22 : if(words.charAt(forward)!=words.charAt(backward))
and the index outbounds since you have defined the the length (size) of the String array "word" is 5.

Your code is able to check a series of strings a client inputs (in which we determine palindrome in terms of series of words) instead of one string (in which we determine palindrome in terms of characters).
I have modified your code as follows:

import java.io.*;
 public class jemz {
 	
 public static void main(String args[]){
  String []words = new String[5];
  Console console = System.console();
						
			int forward=0;
			int backward=words.length-1;
			int i;
			
			System.out.println("Input 5 words");
						
			for(i=0;i<words.length;i++)
			words[i]=new String(console.readLine("Input the " + (i+1) +" word:\n"));
								
			boolean found=true;
			while(forward<backward)	{
				if (words[forward].compareTo(words[backward]) != 0)	{
					found=false;
					break;					
				}
				
				forward++;
				backward--;								
			}
				if(found)
				System.out.println("palindrome");
		    	else
				System.out.println("Not Palindrome");			
		}
}

The testing output:
Input 5 words
Input the 1 word:
jemz
Input the 2 word:
loves
Input the 3 word:
JAVA
Input the 4 word:
loves
Input the 5 word:
jemz
palindrome

tong1 22 Posting Whiz

NewOrder, your idea is good. You have almostly done.
The problem is found in the line 12:

String Snumber="";

When you at the first time come into the nested while loop:

while(allNumbers.charAt(index)!=',')

it works fine. However, when you use the Snumber at the second time, Snumber holds the previous result that should be removed. In fact, the Snumber finally holds your all ditigs after removing all the comma sign ','.
Solution:
Move String Snumber=""; at line 12 by inserting it after line 31
so that each time shortly after outerloop :

while(index<allNumbers.length())

starts you are able to restart the Snumber, that is, make a new Snumber by the decraration: String Snumber=""

tong1 22 Posting Whiz

May I point out the following errors after glancing at your code.
1. javax.servlet is included in J2EE platform rather than J2SE. There for the package does not exist on our J2SE platform.
2. any local variables in a method should not have accessing modifier. Only the data members, that is, the attributes are indicated by accessing modifiers, such as public, friendly, protected, and private.
3. the method checkCCDetails() should be static so that the main method may call it.

tong1 22 Posting Whiz

I have checked your code, done same kind of "proof reading". Good work. Well done.
The final code you have made is printed as follows. Please test your final code again. In software development, TESTING is PROVING/EVALUATING

import java.util.*;
 public class P {
 	public static void main(String arg[]){
 	String names;
 	Scanner console=new Scanner(System.in); // establish a input channel
		    System.out.println("Input palindrome");
		    names=console.next();				
	int		forward = 0;
	int		backward=names.length()-1;	
	boolean	found=true;
		    while(forward<backward) {
		    	if(names.charAt(forward)!=names.charAt(backward)){
		    	found=false;
		    	break;
		    	}
		    	forward++;
		    	backward--; 		    	
		    }	    	
		   if(found)
		    	System.out.println(" palindrome");	
		    else
		    	System.out.println("not palindrome");
		    	
		}
}
tong1 22 Posting Whiz

java.io
Class Console
is wonderful since it lets you to access the character-based console device, if any, associated with the current Java virtual machine.
Console console=System.console();
However, the
java.util
Class Scanner
is also goog since it may carry the same job.
Scanner in = new Scanner(System.in);
I have two comments.
1. to use methods as much as possible.
2. We should define the number as double since number could be in int, float, or double. And parseDouble accepts int as double
Please test the following code to see if there is any error.

import java.io.*;
class Input {
	
	static double average(double d[]){ // the static method returns the mean value of the double array
		double sum=0.0; // the place to store the totting-up values. It was zero at very beginning
		for (int i=0; i<d.length; i++) // the loop to sum up the elements of the array d
			sum += d[i];
		return sum/d.length; // returns the average value
	}
     public static void main(String[] args) {
     Console console=System.console(); // establish an input channel
     int size=5; // input 5 numbers altogether
     double number[]=new double[size]; // define a double array to store the 5 numbers
         
     System.out.println("enter 5 numbers");  
     for(int i=0;i<size;i++)
     number[i]=Double.parseDouble(console.readLine()); // input number could be in the format of int or double
     double ave = average(number); // call the average method to obtain the mean value of the array number
     
     System.out.println("The numbers smaller than the mean …
tong1 22 Posting Whiz

Wikipedia
http://en.wikipedia.org/wiki/Palindrome
says that “A palindrome is a word, phrase, number or other sequence of units that can be read the same way in either direction (the adjustment of punctuation and spaces between words is generally permitted). Composing literature in palindromes is an example of constrained writing.”. From this web site you may see different types of palindrome: characters, phrases, words, Molecular biology, and so on.
Using String instance we may determine if the string (or char array) is a palindrome as we do currently.
We may define a palindromw poet (sentence) in terms of a String array, as you initially intended.. For example:
"Step on no pets"
The following code I have modified is an example showing how to determine a palindrome. I have tested. It works. Please check the code to see if there is any error or to provide comments.

import java.util.*;
 public class PPP {
 	public static void main(String args[]) {
    String pal;
    boolean found=false;
    int forward;
    int backward;
    int i;
    Scanner console = new Scanner(System.in);	 // create an input channel		
    System.out.println("Input palindrome");
	pal=console.next();// receive a string (char array) via DOS window	
	forward = 0; // the head subscript
	backward=pal.length()-1;// the tail subscript		
while(forward<=backward){    /*when two subscripts did not meet, or just meet , i.e. did not cross */
	if(pal.charAt(forward)!=pal.charAt(backward)){ /* if the corresponding chars are not the same */
     found=true; //it is not a palindrome
     break; // jump out of the while loop
     }
      forward++;  // rightward …
tong1 22 Posting Whiz

You have almost done in addition to the String array.
The partial corrected code could be :

String pal;
    boolean found=false;
    int forward;
    int backward;
    int i;
    Scanner console = new Scanner(System.in);			
    System.out.println("Input palindrome");
	pal=console.next();			
	forward = 0;
	backward=pal.length()-1;			
while(forward<=backward)
      {    if(pal.charAt(forward)!=pal.charAt(backward))
		    	
     found=true;
      forward++;
      backward--;
      break;		    	
      }

You may write in your own way, and complete your work.
I am looking forward to seeing your success.
Good luck

tong1 22 Posting Whiz

palindrome is a String instance or an array of char.
You ask the client to input one instance of String rather than an array of String.
Then you should process (work) on this instance to determine if it is polindrome or not. Therefore we are dealing with one instance of String only. We will compare the first char with the last char in the string.

tong1 22 Posting Whiz

In line 3 you should define a String instance pal instead of String array.
Therefore you have to modified the following code related to the pal.
The instance "console" is created by the constructor Scanner, so the lines 10-18 should be replace by one line:
Scanner console = new Scanner(System.in);
line 21: backward=pal.length-1;
should be altered into
backward=pal.length()-1;
since pal is a String instance and length() is a memger method.

in Line 33 shoud be:
if(!found)

I hope you will be able to complete your assignment successfully.

tong1 22 Posting Whiz

The border control variable for the balls’ movement is obtained from the method getHeight() of the JComponent. It returns the current height of this component. I have debugged the code by adding println()s to show how the variables are changing and how the execution flow is going. I have also observed the movements of both balls.
It is found that when resizing the frame the first component still moves within its initial region while the region where the second ball moves has changed accordingly, resulted in such a scenario where the size of the first component (the first ball) remains unchanged while the size (height) of the second component (the second ball) changes accordingly. I have also made the drawing class as an inner class to see if there is any difference. The scenario remains the same. Does the phenomenon show an deficiency in resizing a frame in Java ?

tong1 22 Posting Whiz

I have made the following program which may read the text file "data.txt" (in the format structure you have defined at your first poster) and extract the columns of coordinate values x,y,z into a new file "myfile.txt". Both files are under the same folder as the code file. I hope this program may help you in your work.

/* The class FileUtil is originally defined by 
 * Java source code example
 * http://www.javadb.com/write-lines-of-text-to-file-using-a-printwriter
 * The method writeLinesToFile(...) has been modified.
 */

import java.io.*;
import java.util.*;

class FileUtil {

  public void writeLinesToFile(String filename,
              String[] linesToWrite,int length,
              boolean appendToFile) {

    PrintWriter pw = null;

    try {

      if (appendToFile) {

        //If the file already exists, start writing at the end of it.
        pw = new PrintWriter(new FileWriter(filename, true));

      }
      else {
        pw = new PrintWriter(new FileWriter(filename));
        //this is equal to:
        //pw = new PrintWriter(new FileWriter(filename, false));

      }

      for (int i = 0; i < length; i++) {

        pw.println(linesToWrite[i]);

      }
      pw.flush();

    }
    catch (IOException e) {
      e.printStackTrace();
    }
    finally {     
      //Close the PrintWriter
      if (pw != null)
        pw.close();
      
    	}

  	}
  }

public class CoorToks0 {

   private static StringBuffer buffer;
   private static BufferedReader input=null; 
   private static String st[]= new String[1000]; 
   
   public static void main(String args[]) {
   int count = 0;
   	st[count++] = new String("x\ty\tz\0");
  		try{ 	
       	input = new BufferedReader(
       	new FileReader( new File("data.txt") ) ); 
       	             
        String text;
        while ( ( text = input.readLine() ) != null ) {
	    StringTokenizer s = new StringTokenizer(text," ");
		int counter=0;
		String line="";
        while(s.hasMoreTokens()) {
			String ss …
tong1 22 Posting Whiz

AnyBody please help!!!

tong1 22 Posting Whiz

After one minute you add the second component which is the new ball with the x coordinate of 300. Then you should immediately ask the JFrame to re-arrange the layout via the following code:
frame.validate();
Therefore, you should insert the line of code into line 84 (shortly after the
catch(Exception ex){}
that is:

public static void main(String[] args) {

    JFrame frame=new JFrame();
    frame.setSize(800,600);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);

  try{
  	 frame.add( new drawpanel(10) );
  	 Thread.sleep(3000);
  	 frame.add(new drawpanel(300));
  		}catch(Exception ex){}
  	frame.validate();
    };

It is written in Java API 1.6 as follows.
"The validate method is used to cause a container to lay out its subcomponents again. It should be invoked when this container's subcomponents are modified (added to or removed from the container, or layout-related information changed) after the container has been displayed."

tong1 22 Posting Whiz

Taking the advantage of the powerful function in DOS (or unix/lynix), the following code in Java could be useful for your data extracting. The original text data file is data.txt while the extracted data are stored in the text file:OutputData.dat

import java.io.*;
import java.util.*;
public class CoorToks1 {
   private static BufferedReader input;
   public static void main(String args[]) {
  		try{ 	
            input = new BufferedReader(
                new FileReader( new File(args[0]) ) );                     
         String text;
         System.out.println("x\ty\tz");
        while ( ( text = input.readLine() ) != null ) {
	    StringTokenizer s = new StringTokenizer(text," ");
		int counter=0;
                  while(s.hasMoreTokens()) {
			String ss = s.nextToken();
			counter++;
			if (counter >6 && counter <10)
			System.out.print(ss + "\t");
			}
			System.out.println();  
	  	}
	  }catch( IOException ioException ) {} 
	} 
}

The command on DOS is shown as follows.
java CoorToks1 data.txt >OutputData.dat

tong1 22 Posting Whiz

In your program the last curly brace is missing, resulting in a compiling error.
If you want to print the total number of the elements that are divisible by 5, you have to create a counter to do the job: int counter =0. When scanning the array, if an element divisible by 5 is found you have to make counter one increment: counter++. Finally you may print the value of the counter.

tong1 22 Posting Whiz

We have no need to print out the length of the array. The only data printed out in your program are the length of the array rather than the elements divisible by 5. You have no code that printins any elements in the array.
In line 8 I have replaced your “divisible.length” with “divisible” so that your program may print out all the elements divisible by 5.
The modified program is written as follows:

public class divisible {
public static void main(String args[]) {
int[] divisible;
divisible = new int[] {4,9,25,144};
for (int i=0; i<divisible.length; i++)
  if (divisible[i]%5== 0)
  System.out.println(divisible[i] + " ");
	}
}
tong1 22 Posting Whiz

/* Could be written in the following way */

public class divisible {
	public static void main(String args[]) {
	int[] divisible;
	int toTal=0;
	divisible = new int[] {4,9,25,144};
	System.out.println("The elements divisible by 5 are printed as follows:");
	for (int i=0; i<divisible.length; i++)
		  if (divisible[i]%5== 0){
		  	toTal++;
		  System.out.print(divisible[i] + " ");
		  }
	System.out.println("\nThe total number of the elements divisible by 5 is: " + toTal); 
	}
}

The output is shown as follows:
The elements divisible by 5 are printed as follows:
25
The total number of the elements divisible by 5 is: 1

tong1 22 Posting Whiz

Dear khRiztin,
I do not know how to help you.
I downloaded and extracted it successfully. The size of Scribble.java is 33kb (1263 lines code). The size of the Applet is width="650" height="650".
Yes, it is a zipped file. after unzipping you should put the scribble.html and Scribble.java in the same folder.
On DOS wondow,
First command:
javac Scribble.java
It will compile it with no trouble.
Then, the second command:
appletviewer scribble.html
or use a browser to open the scribble.html
You will see the outcome, and run the applet.

tong1 22 Posting Whiz

The following code may
(1) extract the coordinate values in the 3 float columns in the file "data.txt" under the same folder, and
(2) print the extracted float data only on DOS window.

import java.io.*;
import java.util.*;


public class CoorToks {

   public static StringBuffer buffer;
   public static BufferedReader input; 
   
   public static void main(String args[]) {
  		try{ 	
            input = new BufferedReader(
                new FileReader( new File("data.txt") ) );                     
         String text;
        while ( ( text = input.readLine() ) != null ) {
	    StringTokenizer s = new StringTokenizer(text," ");
		int counter=0;
                  while(s.hasMoreTokens()) {
			String ss = s.nextToken();
			counter++;
			if (counter >6 && counter <10)
			System.out.print(ss + " ");
			}
			System.out.println();  
	  	}
	  }catch( IOException ioException ) {} 
	} 
}
tong1 22 Posting Whiz

You may down load the Java Applet program Scribble.java
http://www.partow.net/projects/jpaintbrush/index.html
It works.
It is pointed out at the web site:
Free use of the Java Paint Brush is permitted under the guidelines and in accordance with the most current version of the "Common Public License."

tong1 22 Posting Whiz

The nested loop can be written as follows:

import java.lang.*;
public class NumberPrinted{ 

public static void main(String args[]){	
  int n = Integer.parseInt(args[0]);
  int number = 10;
  for (int i = 0; i< n; i++){
  for (int j=0; j<10; j++)
  System.out.printf("%4d", number++);
  System.out.println();
		}
	}
}

Using C-style "printf("%4d", a)" to print an number 'a' has the advantage in easily controlling the spaces.
On DOS window the following output may be shown:
java NumberPrinted 9
10 11 12 13 14 15 16 17 18 19
20 21 22 23 24 25 26 27 28 29
30 31 32 33 34 35 36 37 38 39
40 41 42 43 44 45 46 47 48 49
50 51 52 53 54 55 56 57 58 59
60 61 62 63 64 65 66 67 68 69
70 71 72 73 74 75 76 77 78 79
80 81 82 83 84 85 86 87 88 89
90 91 92 93 94 95 96 97 98 99

tong1 22 Posting Whiz
/* The following program demonstrates how to guard 
 * a non-negative input in int. 
 * If the input is in int and also greater than -1, the valid input
 * will be shown on DOS window and program terminates.
 * If client inputs an value in non-int or an negative value in int, the program will
 * ask the user for re-input.
 **/
import java.util.*;
public class Input {
public static void main(String args[]){
int n=0;
Scanner in = new Scanner(System.in);

while(true){
try{
System.out.println("Input a non-negative integer:");
n = in.nextInt();
}catch(InputMismatchException e){
System.out.println("Your input is mismatched.");
in.next();
continue;
}
if (n<0){
System.out.println("You negative value is not valid.");
continue;
}
break;
}

System.out.printf("Your input is %d\n", n);
}
}

The output in DOS:
Input a non-negative integer:
3r3
Your input is mismatched.
Input a non-negative integer:
3.1415
Your input is mismatched.
Input a non-negative integer:
35
Your input is 35

tong1 22 Posting Whiz
import java.io.*;
import java.util.*; 

public class Profile {

    public static void main (String [] args) {

    String name="",user="",pass="",add="";
    int ch=0, con=0;
   Scanner scn = new Scanner(System.in);

    while(true){
        System.out.println("Enter your profile\n");
        System.out.print("Name:");
        name = scn.nextLine();
        System.out.print("Username:");
        user = scn.nextLine();
        System.out.print("Address:");
        pass = scn.nextLine();

    while(true){  // only numeric allowed 
    try{
    System.out.print("Mobile:");
    con = scn.nextInt();
    }catch ( InputMismatchException e ){
          scn.nextLine(); 
          System.out.println("You enter nos. Please retry again.\n" );
          continue;
        } 
        break;
        }
        System.out.println("");
        System.out.println("Press 0 to redo info.");
        System.out.println("Press 1 to save.");
        System.out.println("Press 2 to quit w/o saving.");

        System.out.print("Select a choice:");
        ch = scn.nextInt(); //Read in user prompt (0, 1 or 2)

        switch(ch){
            case 0:
            System.out.println("Editing...");
            continue;
            case 1:
            String info= "\n"+name+";"+user+";"+add+";"+con;
            try {
    PrintWriter out = new PrintWriter(new FileWriter("Profile.txt",true));
            out.write(info);
            out.close();
            System.out.println("Tks for registering.");
            }catch (IOException e) { };
            System.exit(0);
            case 2:
            System.out.println("Tks for registering.");
            System.exit(0); 
            }   
        }
    }
}
tong1 22 Posting Whiz

The following program shows the String instances are converted into different values in boolean, double, and int.
import java.lang.*;
public class Input{
public static void main(String args[]){
if (Boolean.parseBoolean(args[0])) {
System.out.println("The first argument is in boolean: " + Boolean.parseBoolean(args[0]));
System.out.println("The second argument is in double: " + Double.parseDouble(args[1]));
System.out.println("The third argument is in int: " + Integer.parseInt(args[2]));
}
}
}
The executing command:
Java Input true 3.1415 255
The output:
The first argument is in boolean: true
The second argument is in double: 3.1415
The third argument is in int: 255

Also see “http://www.daniweb.com/forums/thread299093.html” where the client is asked to input an integer as the size of an array in int.
-------------------
/* The following program is written to receive a size of an int array that
* assigned by random values varying between 0 to 255 [0-255].
* Then the array will be sorted in ascending order by the bubble method.
*/
import java.lang.*;
public class MainExample1 {
static void bubble_sort(int a[]){
int i,j,t, n=a.length;
boolean change;
for(i=n-1,change=true; i>0 && change ;--i)
{
change=false;
for(j=0;j<i;++j)
if(a[j]<a[j+1])
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
change=true;
}
}
}

public static void main(String args[]){
int n= Integer.parseInt(args[0]);
int d[] = new int[n];
for (int i=0; i<n; i++)

tong1 22 Posting Whiz

As far as I know,
2. On DOS, the command “java” calls the main method only to interpret the code in the main method. When the main method is terminated (executed completely), no return value is requested. Hence the void is always requested.
3. Any arguments received when starting an interpretation of a Java program can be stored only in terms of the instances of the class String. The value of any other types, such as int, doudle, and boolean, can be created via parsing the String instances accordingly. Therefore, only the String instance is appropriated for the type of elements of the array.

tong1 22 Posting Whiz
  1. The difference is in the name of the classes.
  2. The Java language defines the signature (format) of the only main method in a class as
    public static void main(String args[]) {} meanwhile
    the name of the array of String may be given differently, e.g.
    public static void main(String a[]) {},
    public static void main(String bargs[]) {},
    public static void main(String arg[]) {},
    ….
    The following program is taken as an example:

    public class MainExample1 {
    public static void main(String a[]){
    for(int i=0;i<a.length;i++)
    System.out.println("The " + (i+1) + "arguemnt: " + a[i]);
    }
    }

The String array a is used to receive String arguments when the java program is started to execute in the following command on DOS:
Java MainExample1 Dani Web Web Master

The following output on DOS is shown accordingly:
The 1arguemnt: Dani
The 2arguemnt: Web
The 3arguemnt: DaniWeb
The 4arguemnt: Master

tong1 22 Posting Whiz

1. Robert W. Sevesta (2002, Concepts of programming languages, 5th edition, page 107 ) pointed out that “ a token of a language is a category of its lexemes.”
“Formal descriptions of the syntax of programming languages, for simplicity’s sake, often do not include descriptions of the lowest-level syntactic units. These small units are called lexemes.”
2. When the class Scanner in java.util.* is used, you may create a instance:
Scanner in = new Scanner(System.in);
Then using the instance in :
int n = in.nextInt();
To receive an input in int.
When the input string is not a int string, e.g. “44k4”, an InputMissmatchException is thrown:
(see the thread” How to guard the input effectively”
http://www.daniweb.com/forums/thread299076.html
);

public static void main(String args[]){
int n=0;
Scanner in = new Scanner(System.in);

while(true){
try{
System.out.println("Input a non-negative integer:");
n = in.nextInt();
}catch(InputMismatchException e){
System.out.println("Your input is mismatched.");
in.next();
continue;
}
if (n<0){
System.out.println("You negative value is not valid.");
continue;
}
break;
}

System.out.printf("Your input is %d\n", factorial(n));
}
}

tong1 22 Posting Whiz

Is your JLabel's instance on a background painted by the Graphics in AWT?
If the background is made by the Graphics's object, there will be a trouble. The stuff in AWT is considered as heavyweighted while the stuff, such as JLabel's instance in swing, lightweighted. The heaveweighted stuff always "overwrites" the lightweighted one.
Solution:
Use Label in AWT rather than JLabe in swing.