10/25/11



Generating Odd Numbers

10/25/2011


Java code for generating odd numbers:

import javax.swing.JOptionPane;


public class odd{


public static void main(String[] args){

int x = 0;

do{
String inputNum = JOptionPane.showInputDialog(null, "Enter any positive number: ",  "Input", JOptionPane.INFORMATION_MESSAGE);
x = Integer.parseInt(inputNum);
if(x<1){
JOptionPane.showMessageDialog(null, "ERROR. It must be a positive integer.", "Error", JOptionPane.ERROR_MESSAGE);
}
}while(x<1);
System.out.println("\nYou entered " + x + ".");
System.out.println("\n\nOdd numbers found: ");
System.out.println("------------------");
for(int j = 1; j<=x;){
System.out.print(j + ", ");
j = j + 2;
if(j>x)
break;
}
System.out.println("\n\n");
}



}




Sample Output:




Your thoughts about this post? Leave a commment now.

Posted by

AndyFGo : A place for Pinoy Music News. Lyrics. Music Videos. Pinoy Movie/Foreign Trailers. OPM.

 

© 2013 andyfgo. All rights reserved. Designed by Templateism. Powered by Blogger
Protected by Copyscape DMCA Takedown Notice Violation Search

Back To Top