The Artima Developer Community
Sponsored Link

Java Answers Forum
NEED HELP ON CODE

1 reply on 1 page. Most recent reply: Oct 25, 2006 5:45 AM by Rajeev Mutalik

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
rohitmc jaames

Posts: 1
Nickname: rohitmc
Registered: Sep, 2006

NEED HELP ON CODE Posted: Sep 24, 2006 10:50 AM
Reply to this message Reply
Advertisement
HI HOW'S EVERYBODY DOIN?

I AM WORKING ON THIS CODE, THERE ARE SOME ERROR PLS HELP ME FIX THESE.
THE PROGRAM SUPPOSE TO DO.
1. Ask the user to type in a sentence, using a JOptionPane.showInputDialog().
2. The program will scan the string and count how many upper-case letters appear, and how many
lower-case letters appear.
3. Tell the user how many upper/lower case letters there were using a
JOptionPane.showMessageDialog()
4. Repeat this process until the user types the word "Stop".

MY PROGRAM IS VERY MESSED UP, IF YOU WANT REWRITE THE PROGRAM PLS DO SO, I REALLY APERICATE THE HELP, THANKS
AFTER FIXING THE CODE PLS PUT THE NOTES IN THE PROGRAM SO I CAN UNDERSTAND EVERYTHING

here's the program


import javax.swing.*;

public class project {
public static void main (String [] args)
{
String line = JOptionPane.showinputDialog ( "Please enter a sentence.")
line = input.nextLine();

While (! line.equals ("STOP") )
System.out.println("Your string contains "
+ lowercaseLCVowelCount(line)
+ " Number of lower case letters:");
System.out.println("Your string contains "
+ uppercaseLCVowelCount(line)
+ " Number of Upper case letters");
System.exit(0);
}

public static int lowercasepro(String text)
{
int count = 0;
for ( int i = 0; i < text.length(); i++ )
{
char x = text.charAt(i);
if ( x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u'
)
count++;
}

public static int uppercasepro(String text)
{
int count = 0;
for ( int i = 0; i < text.length(); i++ )
{
char x = text.charAt(i);
if ( x == 'A' || x == 'E' || x == 'I' || x == 'O' || x == 'U'
)
count++;
return count;
}
}


Rajeev Mutalik

Posts: 57
Nickname: rajmutalik
Registered: Sep, 2002

Re: NEED HELP ON CODE Posted: Oct 25, 2006 5:45 AM
Reply to this message Reply
Here is the correct code for that:

package com.logicacmg.ui;

import javax.swing.*;

public class UIProject {
public static void main (String [] args) {
String line = JOptionPane.showInputDialog( "Please enter a sentence.");
//line = input.nextLine();
while (! line.equals ("STOP") ) {
System.out.println("Your string contains "
+ lowercasepro(line)
+ " Number of lower case letters:");
System.out.println("Your string contains "
+ uppercasepro(line)
+ " Number of Upper case letters");
System.exit(0);
}
}

public static int lowercasepro(String text) {
int count = 0;
for ( int i = 0; i < text.length(); i++ ) {
char x = text.charAt(i);
if ( x >= 'a' && x <= 'z')
count++;
}
return count;
}

public static int uppercasepro(String text) {
int count = 0;
for ( int i = 0; i < text.length(); i++ ) {
char x = text.charAt(i);
if ( x >= 'A' && x <= 'Z')
count++;
//return count;
}
return count;
}
}

Flat View: This topic has 1 reply on 1 page
Topic: Bad File Descriptor error Previous Topic   Next Topic Topic: Method Overriding

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use