codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Pangrams  sidewayson2wheels at 04:01 on Sunday, March 05, 2006
 

I have to write a program that asks the user to enter in a string then tells you if it is a panagram (includes all the alphabet), if not displays the letters missing.


Where do I start.

I have written the following which works ok untill you switch the order of the characters then it dont find it.



import java.lang.*;
import java.util.*;

public class pangram {
public static void main(String[] args) {
String name ="abcdefgihjklmnopqrstuvwxyzafd";
int index = name.indexOf("abd"); // 1
System.out.print("hello");
if (index<0)
{System.out.print("Not found");}
if (index>=0)
{System.out.print("Found");}
}
}

  Re: Pangrams  crwood at 05:24 on Tuesday, March 07, 2006
 


public class PangramTest
{
static String domain = "abcdefghijklmnopqrstuvwxyz";

public static void main(String[] args)
{
String[] testStrs =
{
"hello world",
"the five boxing wizards jump quickly",
"the quick brown fox jumps over a lazy dog"
};
for(int j = 0; j < testStrs.length; j++)
System.out.println(isPangram(testStrs[j]));
}

private static boolean isPangram(String s)
{
// run through domain and look for each letter in s
// if we find them all, return true
// if we miss one, return false
char[] chars = domain.toCharArray();
for(int j = 0; j < chars.length; j++)
{
char next = chars[j];
if(s.indexOf(next) == -1)
{
System.out.println("couldn't find " + next);
return false;
}
}
return true;
}
}


  Re: Pangrams  sidewayson2wheels at 00:25 on Wednesday, March 08, 2006
 

Hi, I compiled the program but the only problem I have is it only displays one of the letters missing.

Also how do I change the message "True" to "This string is a pangram" as it looked like they were being returned.

Many thanks

  Re: Pangrams  crwood at 01:46 on Wednesday, March 08, 2006
 


public class PangramTest
{
static String domain = "abcdefghijklmnopqrstuvwxyz";

public static void main(String[] args)
{
String[] testStrs =
{
"hello world",
"the five boxing wizards jump quickly",
"the quick brown fox jumps over a lazy dog"
};
for(int j = 0; j < testStrs.length; j++)
{
String result = "This string is " +
(isPangram(testStrs[j]) ? "" : "not ") +
"a pangram.";
System.out.println(result);
}
}

private static boolean isPangram(String s)
{
// run through domain and look for each letter in s
// if we find them all, return true
// if we miss one, return false
boolean result = true;
char[] chars = domain.toCharArray();
for(int j = 0; j < chars.length; j++)
{
char next = chars[j];
if(s.indexOf(next) == -1)
{
if(result)
{
System.out.print("couldn't find " + next + ", ");
result = false;
}
else
System.out.print(next + ", ");
}
}
if(!result)
System.out.println();
return result;
}
}









CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  HELP
•  session maintainance
•  javascript error on client machine only
•  Onclick using images and sounds
•  Re: dynamic crystal report generation
•  Re: [GRAPHICS] - SymbolDesignerTool - URGENT HELP PLS
•  can i use javascript to create acrobat a catalog/index
•  can anyone help?
•  Variables from html


Recent Articles
What is a pointer in C?
Multiple submit buttons with form validation
Understanding Hibernate ORM for Java/J2EE
HTTP screen-scraping and caching
a javascript calculator
A simple way to JTable
Java Native Interface (JNI)
Parsing Dynamic Layouts
MagicGrid
Caching With ASP.Net


© Copyright codetoad.com 2001-2006