-
Re: java programming assignment help
Quote:
how will i test the length
Look at the API doc for the String class. It has a method that will give you the length.
Quote:
how will it confirm that the input is not a character?
Define what you mean by a character? The only data that can be entered easily via the keyboard is a character. Look at the Character class's methods if you want to know what kind of character was read into the program.
The API doc: Java Platform SE 7
-
Re: java programming assignment help
-
Re: java programming assignment help
It's at this link:
The API doc: Java Platform SE 7
-
Re: java programming assignment help
how to fix this??
when i input 81
my program output the squareroot is 2.828 something...
Code :
/**
* @(#)activity2.java
*
*
* @author
* @version 1.00 2012/10/1
*/
import javax.swing.*;
public class aa
{
public static void main(String[]args)
{
String input="";
char inputs;
double x;
int loop=0;
do{
input=JOptionPane.showInputDialog(null,"Enter A Character: ");
inputs=input.charAt(0);
if(Character.getType(inputs) == Character.CURRENCY_SYMBOL)
{
JOptionPane.showMessageDialog(null,"The character is a symbol.");
}
else if(Character.isDigit(inputs))
{
int num= inputs -'0';
JOptionPane.showMessageDialog(null,"The character is a Digit.");
JOptionPane.showMessageDialog(null,"The square root of "+inputs+" is "+Math.sqrt(num));
}
else if (input.length()>1)
{
JOptionPane.showMessageDialog(null,"Invalid Input. Input a character only.");
}
else if(Character.isLetter(inputs))
{
if(Character.isLowerCase(inputs))
{
JOptionPane.showMessageDialog(null,"Lowercase");
}
if(Character.isUpperCase(inputs))
{
JOptionPane.showMessageDialog(null,"UpperCase");
}
}
else
{
JOptionPane.showMessageDialog(null,"The character is a symbol.");
}
loop = JOptionPane.showConfirmDialog(null,"Try Again?[Y/N]","repeat",JOptionPane.YES_NO_OPTION);
if(loop == JOptionPane.NO_OPTION)
{
JOptionPane.showMessageDialog(null,"Thank You For Using The Program.");
}
}while(loop == JOptionPane.YES_OPTION);
}
}
-
Re: java programming assignment help
Please edit you post and change the quote tags to code tags.
Also please format the code. All statements should NOT start in the first column.
What is the square root of 8?
Your code only works with one character
-
Re: java programming assignment help
how will i make it accept 2 or more values which will not affect the other codes but only the square root of a 2 digit or more number
-
Re: java programming assignment help
The code reads the full input from the user into a variable and then takes the first character.
If you want all of the input, use it instead of just using the first character.
Please edit your code and format it. All statements should not start in the first column.
See: Code Conventions for the Java Programming Language: 4. Indentation
-
Re: java programming assignment help
already fixed it another new problem
if i input String10 my program output "Invalid Input. Input a character only" but if i input 10String my program will output "The Character is a Digit" the if i press ok an error will come out.....
the problem is...if i Input 10String my problem will output "Invalid Input. Input a character only" because it is not a char
please help me my program due tom
Code :
/**
* @(#)activity2.java
*
*
* @author
* @version 1.00 2012/10/1
*/
import javax.swing.*;
public class Activity2
{
public static void main(String[]args)
{
String input="";
char inputs;
double x;
int loop=0;
do{
input=JOptionPane.showInputDialog(null,"Enter A Character: ");
inputs=input.charAt(0);
if(Character.getType(inputs) == Character.CURRENCY_SYMBOL)
{
JOptionPane.showMessageDialog(null,"The character is a symbol.");
}
else if(Character.isDigit(inputs))
{
JOptionPane.showMessageDialog(null,"The character is a Digit.");
JOptionPane.showMessageDialog(null,"The square root of "+input+" is "+Math.sqrt(Double.parseDouble(input)));
}
else if (input.length()>1)
{
JOptionPane.showMessageDialog(null,"Invalid Input. Input a character only.");
}
else if(Character.isLetter(inputs))
{
if(Character.isLowerCase(inputs))
{
JOptionPane.showMessageDialog(null,"Lowercase");
}
if(Character.isUpperCase(inputs))
{
JOptionPane.showMessageDialog(null,"UpperCase");
}
}
else
{
JOptionPane.showMessageDialog(null,"The character is a symbol.");
}
loop = JOptionPane.showConfirmDialog(null,"Try Again?[Y/N]","repeat",JOptionPane.YES_NO_OPTION);
if(loop == JOptionPane.NO_OPTION)
{
JOptionPane.showMessageDialog(null,"Thank You For Using The Program.");
}
}while(loop == JOptionPane.YES_OPTION);
}
}
-
Re: java programming assignment help
If you want the program to give an error message for input of more than one character, have it test the length of the String it reads in from the user.
Please edit your code and format it. All statements should not start in the first column.
See: Code Conventions for the Java Programming Language: 4. Indentation
-
Re: java programming assignment help
i already have this one "else if (input.length()>1)
{
JOptionPane.showMessageDialog(null,"Invalid Input. Input a character only.");"
help please
-
Re: java programming assignment help
There are more than one if statement. Which one do you want done first?
With if/else if statements, the first one that is true is the only one that will be executed. The following ones will be skipped.
Your code is hard to read and understand.
Please edit your code and format it. All statements should not start in the first column.
See: Code Conventions for the Java Programming Language: 4. Indentation
-
Re: java programming assignment help
already edited the if but still i have the error
Code :
/**
* @(#)activity2.java
*
*
* @author
* @version 1.00 2012/10/1
*/
import javax.swing.*;
public class activity2
{
public static void main(String[]args)
{
String input="";
char inputs;
double x;
int loop=0;
do{
input=JOptionPane.showInputDialog(null,"Enter A Character: ");
inputs=input.charAt(0);
if(Character.getType(inputs) == Character.CURRENCY_SYMBOL)
{
JOptionPane.showMessageDialog(null,"The character is a symbol.");
}
else if(Character.isDigit(inputs))
{
JOptionPane.showMessageDialog(null,"The character is a Digit.");
JOptionPane.showMessageDialog(null,"The square root of "+input+" is "+Math.sqrt(Double.parseDouble(input)));
}
else if (input.length()>1)
{
JOptionPane.showMessageDialog(null,"Invalid Input. Input a character only.");
}
else if(Character.isLetter(inputs))
{
if(Character.isLowerCase(inputs))
{
JOptionPane.showMessageDialog(null,"Lowercase");
}
else if(Character.isUpperCase(inputs))
{
JOptionPane.showMessageDialog(null,"UpperCase");
}
}
else
{
JOptionPane.showMessageDialog(null,"The character is a symbol.");
}
loop = JOptionPane.showConfirmDialog(null,"Try Again?[Y/N]","repeat",JOptionPane.YES_NO_OPTION);
if(loop == JOptionPane.NO_OPTION)
{
JOptionPane.showMessageDialog(null,"Thank You For Using The Program.");
}
}while(loop == JOptionPane.YES_OPTION);
}
}
-
Re: java programming assignment help
Your code is hard to read and understand.
Please edit your code and format it. All statements should not start in the first column.
See: Code Conventions for the Java Programming Language: 4. Indentation
-
Re: java programming assignment help
-
Re: java programming assignment help
Why won't you fix the posted code to make it easier to read and understand?
The statements should NOT all start in the first column. Add spaces to indent as per the link that has been posted several times.
Did you understand what I said in post#36?
-
Re: java programming assignment help
help please
Code :
/**
* @(#)activity2.java
*
*
* @author
* @version 1.00 2012/10/1
*/
import javax.swing.*;
public class activity2
{
public static void main(String[]args)
{
String input="";
char inputs;
double x;
int loop=0;
do{
input=JOptionPane.showInputDialog(null,"Enter A Character: ");
inputs=input.charAt(0);
if(Character.getType(inputs) == Character.CURRENCY_SYMBOL)
{
JOptionPane.showMessageDialog(null,"The character is a symbol.");
}
else if(Character.isDigit(inputs))
{
JOptionPane.showMessageDialog(null,"The character is a Digit.");
JOptionPane.showMessageDialog(null,"The square root of "+input+" is "+Math.sqrt(Double.parseDouble(input)));
}
else if (input.length()>1)
{
JOptionPane.showMessageDialog(null,"Invalid Input. Input a character only.");
}
else if(Character.isLetter(inputs))
{
if(Character.isLowerCase(inputs))
{
JOptionPane.showMessageDialog(null,"Lowercase");
}
else if(Character.isUpperCase(inputs))
{
JOptionPane.showMessageDialog(null,"UpperCase");
}
}
else
{
JOptionPane.showMessageDialog(null,"The character is a symbol.");
}
loop = JOptionPane.showConfirmDialog(null,"Try Again?[Y/N]","repeat",JOptionPane.YES_NO_OPTION);
if(loop == JOptionPane.NO_OPTION)
{
JOptionPane.showMessageDialog(null,"Thank You For Using The Program.");
}
}while(loop == JOptionPane.YES_OPTION);
}
}
-
Re: java programming assignment help
Do you understand what I said in post #36?
Quote:
There is more than one if statement. Which one do you want done first?
With if/else if statements, the first one that is true is the only one that will be executed. The following ones will be skipped.
Your formatting is still wrong. It should look like this:
Code :
}
loop = JOptionPane.showConfirmDialog(null,"Try Again?[Y/N]","repeat",JOptionPane.YES_NO_OPTION);
if(loop == JOptionPane.NO_OPTION)
{
JOptionPane.showMessageDialog(null,"Thank You For Using The Program.");
}
}while(loop == JOptionPane.YES_OPTION);
}
}
-
Re: java programming assignment help
can you now just help me to my problem?
-
Re: java programming assignment help
I thought I did. If what I said in post #36 is not the problem, can you please explain what the problem is? Make a list the the steps you do and the steps the computer does and then explain what is wrong with the computer's responses. For example:
1) I enter: s
2) the computer says: lowercase
3) I enter: 4
4) the computer says: 2
5) I enter:this is another
6) The computer says: lowercase <<<<<< This should be: Invalid input
-
Re: java programming assignment help
oh you dont get what i said awhileago
the problem is
1. I enter: 10String
2. The Computer Says its A Digit then After i press Ok My Program shown an error
...the problem to my program is if i enter 10String,,the program should output invalid input because 10String is not a pure number it also has letter on it..
so what is the solution for it??
program works fine if i enter String10..and the program will output invalid input
-
Re: java programming assignment help
Quote:
program should output invalid input because 10String is not a pure number it also has letter on it..
Would 1234 be a valid input?
One way to check if a String contains only numeric digits would be to use the Integer class's parseInt() method inside of a try{}catch block. The parseInt() method will throw an exception if the String it gets is not a valid/pure number.
Another way to check if a String contains only numeric digits would be to write a loop that gets the characters in the String one at a time and tests each character with the isDigit() method.
-
Re: java programming assignment help
yes 1234 will be a valid input because it contains pure numbers....
about your solution how to do it??also i am using joption not buffered
-
Re: java programming assignment help
If you don't understand how to use the try{} catch block use the second way.
Quote:
i am using joption not buffered
I don't understand what that is about.
-
Re: java programming assignment help
i do not know where to start..please guide me
-
Re: java programming assignment help
Write a small program for testing.
Define a String with several characters that will be scanned in the loop.
Define a loop that gets the characters one at a time from the String.
The loop needs to go around one time for each character in the String.