Hello,
I am having trouble with my Odd/ Even Code. Can anyone help me with this?
Here is what I have so far, but the program is not recognizing the (number) after if ( number). So if anyone can help I would sure appreciate it.
mport javax.swing.JOptionPane; // program uses JOptionPane
public class EvenOdd {
/** Creates a new instance of EvenOdd */
public EvenOdd() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
String firstNumber; // first string entered by user
int number; // number to be read
int even; // number if even
int odd; // number if odd
firstNumber = JOptionPane.showInputDialog( null, " Enter a number" );
if ( number%2 == 0 );
System.out.print( " Number is EVEN " );
Well, you are trying to use "number" in your if statement. You do not have number set to any value. Maybe you meant "firstNumber" instead of "number".That should get you going in the right direction
import javax.swing.JOptionPane; // program uses JOptionPane
public class EvenOdd {
public static void main(String[] args) {
String firstNumber;
int number;
firstNumber = JOptionPane.showInputDialog( null, " Enter a number" );
number = Integer.parseInt(firstNumber);
if ( number%2 == 0 ){
System.out.print( " Number is EVEN " );
}
else
System.out.print("Number is ODD");
}
}
Can any one help me Plz
- write an java program that outputs the followingpattern. Th program should prompt the user an osdd nmbr of lines (limit 1 to 11).
For example, if the user prompt the number of lines is 9, the the outputs should be :
+
++
+++
++++
+++++
++++
+++
++
+
public class kaze{
public static void main(String[] args) throws IOException{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
Integer number;
System.out.println("Input A Number:");
number = Integer.parseInt(in.readLine());
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.