|
|
Hello, Guest! Welcome to Symbianize forums.
Most of our features and services are available only to our members. So we encourage you to login or join us by registering a new account. Registration is free, fast, and simple. You only need to provide a valid email address so we can minimize spammers. As a Symbianize member you'll have the following privileges:
- Gain access to private forums and restricted features
- Reply and create new topics or polls
- Download free applications, games, themes, graphics, tones, videos, etc.
- Ask question or support related to mobile phone, computer, game console, and multimedia
- Private messaging (PM) with fellow members
- Communicate instantly or real-time with currently online members via Shout Box
All that and more, so what are you waiting for, join us now! Ito ang website na ginawa ng pinoy para sa pinoy!
| |
| Programming Discussions related to C++, HTML, PHP, ASP, ColdFusion, JavaScript, Perl, Phyton, Ruby, WML, SQL, XML, and other programming languages. |
 |

20th Jun 2012 Wed, 21:55
|
 |
Professional
|
|
Join Date: Jan 2012
Location: Somewhere down the road..
Posts: 153
Reputation:
|
|
Java Help
mga ka-symb.. patulong nman po bkit palaging nag-aask ng number yung program.. ano po kaya mali dito
Code:
import javax.swing.JOptionPane;
public class qwe
{
public static void main (String args[])
{
mean();
}
public static void mean() {
int[] m= new int[10];
int sum = 0;
int i;
String num;
for (int j = 0; j < m.length; j++)
{
for ( i = 0; i < m.length; i++)
{
num = JOptionPane.showInputDialog("Enter a number");
m[i]=Integer.parseInt( num );
sum += m[i];
}
}
JOptionPane.showInputDialog(null, "The mean is " +sum/m.length);
}
}
Mean po pla ang dapat na i-output ng program..
tulong po.. baguhan lamang po sa Java  
|

20th Jun 2012 Wed, 22:26
|
 |
Forum Consultant
|
|
Join Date: Jul 2009
Location: Baguio City
Posts: 1,485
Reputation:
|
|
Re: Java Help
Quote:
Originally Posted by evilseloso
mga ka-symb.. patulong nman po bkit palaging nag-aask ng number yung program.. ano po kaya mali dito
Code:
import javax.swing.JOptionPane;
public class qwe
{
public static void main (String args[])
{
mean();
}
public static void mean() {
int[] m= new int[10];
int sum = 0;
int i;
String num;
for (int j = 0; j < m.length; j++)
{
for ( i = 0; i < m.length; i++)
{
num = JOptionPane.showInputDialog("Enter a number");
m[i]=Integer.parseInt( num );
sum += m[i];
}
}
JOptionPane.showInputDialog(null, "The mean is " +sum/m.length);
}
}
Mean po pla ang dapat na i-output ng program..
tulong po.. baguhan lamang po sa Java   
|
tangalin mo eto sa loop
lagay mo bago ung loop
Code:
num = JOptionPane.showInputDialog("Enter a number");
|

20th Jun 2012 Wed, 23:02
|
 |
Professional
|
|
Join Date: Jan 2012
Location: Somewhere down the road..
Posts: 153
Reputation:
|
|
Re: Java Help
Quote:
Originally Posted by polens
tangalin mo eto sa loop
lagay mo bago ung loop
Code:
num = JOptionPane.showInputDialog("Enter a number");
|
 po sir..
pwede po bah maka-ask ulit ng isang tanong?
Code:
import javax.swing.JOptionPane;
public class qwe
{
public static void main (String args[])
{
mode();
}
public static void mode()
{
int[] a= new int[10];
int maxValue, maxCount=0;
String num;
for (int i = 0; i < a.length; ++i)
{
int count = 0;
for (int j = 0; j < a.length; ++j)
{for ( i = 0; i < a.length; i++)
{
num = JOptionPane.showInputDialog("Enter a number");
a[i]=Integer.parseInt( num );
if (a[j] == a[i]) ++count;
}}
if (count > maxCount)
{
maxCount = count;
maxValue = a[i];
}
JOptionPane.showMessageDialog(null, "The mode is " + maxValue);
}
}
}
Ayw pong mag-ask ng program ng mga integers sa user tpos uninitialized pa daw yung maxValue na integer... ano po kaya prob nman nito sir?
|

20th Jun 2012 Wed, 23:05
|
 |
Professional
|
|
Join Date: Jan 2012
Location: Somewhere down the road..
Posts: 153
Reputation:
|
|
Re: Java Help
tungkol po pala sa Mode ang nxt problem ko sir.
|

20th Jun 2012 Wed, 23:35
|
 |
Veteran
|
|
Join Date: Jan 2012
Location: Sa Puso mo
Posts: 385
Reputation:
|
|
Re: Java Help
ung sa maxValue mo po sir.. ung data type lng po ung gnagya nung maxcount and ndi po nagagaya nang maxValue mo ung value nung maxCount so dapat ang gawin mo sir eh.
e.g
int maxValue = 15, maxCount = 0
yan po dpat ang gwin mo.. for example lng po yan.
|

21st Jun 2012 Thu, 05:59
|
 |
Professional
|
|
Join Date: Jan 2012
Location: Somewhere down the road..
Posts: 153
Reputation:
|
|
Re: Java Help
ano po ibig sabihin nyo sir.. nagla-lag na utak ko
|

21st Jun 2012 Thu, 08:17
|
|
Expert
|
|
Join Date: May 2012
Posts: 213
Reputation:
|
|
Re: Java Help
first tanggalin mo yung outer loop. Next palitan mo yung second showInputDialog ng showMessageDialog. Then ok na yan.
|

21st Jun 2012 Thu, 10:52
|
 |
The Grand Master
|
|
Join Date: Sep 2010
Location: City of the Outcast
Posts: 3,198
Reputation:
|
|
Re: Java Help
Quote:
Originally Posted by evilseloso
 po sir..
pwede po bah maka-ask ulit ng isang tanong?
Code:
import javax.swing.JOptionPane;
public class qwe
{
public static void main (String args[])
{
mode();
}
public static void mode()
{
int[] a= new int[10];
int maxValue, maxCount=0;
String num;
for (int i = 0; i < a.length; ++i)
{
int count = 0;
for (int j = 0; j < a.length; ++j)
{for ( i = 0; i < a.length; i++)
{
num = JOptionPane.showInputDialog("Enter a number");
a[i]=Integer.parseInt( num );
if (a[j] == a[i]) ++count;
}}
if (count > maxCount)
{
maxCount = count;
maxValue = a[i];
}
JOptionPane.showMessageDialog(null, "The mode is " + maxValue);
}
}
}
Ayw pong mag-ask ng program ng mga integers sa user tpos uninitialized pa daw yung maxValue na integer... ano po kaya prob nman nito sir? 
|
Mode ba ng statistics ito?
so ang itini-test mo ay ung number na may pinakamaraming occurrence tama?
Try mo ito
Code:
public static void mode() {
int[] a = new int[10];
int maxValue = 0;
int maxCount = 0;
for( int i=0; i<a.length; i++ ) {
a[i] = Integer.parseInt( JOptionPane.showInputDialog("Enter a number") );
int ctr = 0; // Counter
for( int j=0; j<a.length; j++ ) {
if( a[i] == a[j] )
ctr++;
}
if( ctr > maxCount ) {
maxValue = a[i];
maxCount = a[i];
}
}
JOptionPane.showMessageDialog(null, "The mode is " + maxValue);
}
Last edited by i_ignore08; 21st Jun 2012 Thu at 10:53..
|
 |
All times are GMT +8. The time now is 05:39.
|