ElaKiri Community
Downloads
Go Back   ElaKiri Community > General > Education
Reload this Page Java Help
Reply
 
Thread Tools
(#1)
Old
Dhanuka Nilanjana's Avatar
Dhanuka Nilanjana Dhanuka Nilanjana is offline
Senior Member
Dhanuka Nilanjana has a spectacular aura aboutDhanuka Nilanjana has a spectacular aura about
 
Posts: 738
Join Date: Aug 2009
Location: Dompe,Sri Lanka
Send a message via Skype™ to Dhanuka Nilanjana
oo Java Help - 04-24-2012, 03:29 AM

මචන්ලා මට java programme එකක් හදන්න වෙලා තියෙනවා මේකෙන් වෙන්න ඕන දේ සරලව කිව්වොත් කාසියක් උඩ දැම්මම 1000 වාරයක් සිරස ලැබෙන්න කී වාරයක් කාසිය උඩ දාන්න ඕනිද​? කියලා තමයි ගණනය වෙන්න ඕනි. පහල තියෙන්නෙ මේකෙ ප්‍රශ්නය​

Write a simulator programme that flip a coin:
1. One thousand time then print out how many time you got tail and how many time you got head.

2. Continuously flipping coin until you find 1000 head count then print out how many time the coin has been flipped.


මේක හදාගන්න කවුරුහරි help එකක් දෙන්න​.


Reply With Quote
(#2)
Old
Dhanuka Nilanjana's Avatar
Dhanuka Nilanjana Dhanuka Nilanjana is offline
Senior Member
Dhanuka Nilanjana has a spectacular aura aboutDhanuka Nilanjana has a spectacular aura about
 
Posts: 738
Join Date: Aug 2009
Location: Dompe,Sri Lanka
Send a message via Skype™ to Dhanuka Nilanjana
Up 04-24-2012, 04:37 AM

Bump
Reply With Quote
(#3)
Old
Ayeshlive's Avatar
Ayeshlive Ayeshlive is offline
Senior Member
Ayeshlive is a glorious beacon of lightAyeshlive is a glorious beacon of lightAyeshlive is a glorious beacon of lightAyeshlive is a glorious beacon of lightAyeshlive is a glorious beacon of lightAyeshlive is a glorious beacon of lightAyeshlive is a glorious beacon of lightAyeshlive is a glorious beacon of lightAyeshlive is a glorious beacon of lightAyeshlive is a glorious beacon of lightAyeshlive is a glorious beacon of light
 
Posts: 5,802
Join Date: Jul 2011
Location: Earth Realm
04-24-2012, 06:17 AM

Java nam echchara danne na machan. bump ekak.
aye help illala thread danakota lankawe welawen 6-10 pm withara dapan. me welawata online inne tika denaine.,
Reply With Quote
(#4)
Old
amilabanuka's Avatar
amilabanuka amilabanuka is offline
Senior Member
amilabanuka has a spectacular aura aboutamilabanuka has a spectacular aura aboutamilabanuka has a spectacular aura aboutamilabanuka has a spectacular aura about
 
Posts: 3,545
Join Date: Sep 2006
Location: Thama math hoyanooo....
Send a message via ICQ to amilabanuka Send a message via Skype™ to amilabanuka
04-24-2012, 06:37 AM

without UI
generate a random number in anyway you like. if the scale is low make is bit larger. then take the modulo 2 so you'll get either 1 or 0. nominate those as you like. then you have coin flipping.
then you can loop it and get the results
Reply With Quote
(#5)
Old
nokiyaphone nokiyaphone is offline
Member
nokiyaphone is on a distinguished road
 
Posts: 67
Join Date: Mar 2011
04-24-2012, 06:57 AM

Thama Bari unanam kiyanne............................
Reply With Quote
(#6)
Old
professor's Avatar
professor professor is offline
Senior Member
professor will become famous soon enough
 
Posts: 373
Join Date: Apr 2012
Location: lab එකේ
04-24-2012, 07:23 AM

sorry bro.. dan na
Reply With Quote
(#7)
Old
Dhanuka Nilanjana's Avatar
Dhanuka Nilanjana Dhanuka Nilanjana is offline
Senior Member
Dhanuka Nilanjana has a spectacular aura aboutDhanuka Nilanjana has a spectacular aura about
 
Posts: 738
Join Date: Aug 2009
Location: Dompe,Sri Lanka
Send a message via Skype™ to Dhanuka Nilanjana
Up 04-24-2012, 09:15 AM

Quote:
Originally Posted by amilabanuka View Post
without UI
generate a random number in anyway you like. if the scale is low make is bit larger. then take the modulo 2 so you'll get either 1 or 0. nominate those as you like. then you have coin flipping.
then you can loop it and get the results
I have done the first part. but the second part is bit treaky
Reply With Quote
(#8)
Old
Dhanuka Nilanjana's Avatar
Dhanuka Nilanjana Dhanuka Nilanjana is offline
Senior Member
Dhanuka Nilanjana has a spectacular aura aboutDhanuka Nilanjana has a spectacular aura about
 
Posts: 738
Join Date: Aug 2009
Location: Dompe,Sri Lanka
Send a message via Skype™ to Dhanuka Nilanjana
04-24-2012, 09:16 AM

Quote:
Originally Posted by nokiyaphone View Post
Thama Bari unanam kiyanne............................
E honda eka wage help ekak deepan tawama bari una
Reply With Quote
(#9)
Old
tharindudoo's Avatar
tharindudoo tharindudoo is offline
Senior Member
tharindudoo is a glorious beacon of lighttharindudoo is a glorious beacon of lighttharindudoo is a glorious beacon of lighttharindudoo is a glorious beacon of lighttharindudoo is a glorious beacon of lighttharindudoo is a glorious beacon of lighttharindudoo is a glorious beacon of lighttharindudoo is a glorious beacon of lighttharindudoo is a glorious beacon of lighttharindudoo is a glorious beacon of lighttharindudoo is a glorious beacon of light
 
Posts: 10,212
Join Date: Mar 2007
Location: ..ජනේලේ ගාව....
Send a message via ICQ to tharindudoo Send a message via AIM to tharindudoo Send a message via MSN to tharindudoo Send a message via Yahoo to tharindudoo
04-24-2012, 11:14 AM

2nd part ekedi loop ekak athule random number generate function 1k danna dala a ena number eka %2 aragena 1 ena ava head vidiyatath 0 ena ava tail vidiyatath ganna,
variable (x)1k dala increment karanna rand number eka generate vena hama velaavakama,thava variable 2k dala 1 avoth eka variable 1k increment karanna 0 avoth anith variable eka increment karann,1 kiyanne head ne,1 avahama incremen vena variable eka == 1000ta print karanna x ge count eka a kiyanne head 1000k vatenna generate vena numbers gaana x variable eken print karanava,

me logic eka,
code 1k uba gahapan
Reply With Quote
(#10)
Old
MihiCherub's Avatar
MihiCherub MihiCherub is offline
Senior Member
MihiCherub is a glorious beacon of lightMihiCherub is a glorious beacon of lightMihiCherub is a glorious beacon of lightMihiCherub is a glorious beacon of lightMihiCherub is a glorious beacon of lightMihiCherub is a glorious beacon of lightMihiCherub is a glorious beacon of lightMihiCherub is a glorious beacon of lightMihiCherub is a glorious beacon of lightMihiCherub is a glorious beacon of lightMihiCherub is a glorious beacon of light
 
Posts: 5,319
Join Date: Sep 2009
Location: No:██████, Gampaha
Send a message via Skype™ to MihiCherub
Up 04-24-2012, 11:46 AM

Quote:
import java.util.Random;
class flipaCoin{

static int h1, t1;

public static void main (String [] mihi){

Random flippinCoin = new Random();

for (int i = 0; i < 1000; i++) {
int flip = flippinCoin.nextInt(2) + 1;

if(flip==1){
System.out.println("Head");
h1++;
}else{
System.out.println("Tail");
t1++;
}
}
System.out.println("Head = "+h1+"\nTail = "+t1);
}
}
------------------------------------------------------------

Quote:
import java.util.Random;
class flipaCoin{

static int h1, t1;

public static void main (String [] mihi){

Random flippinCoin = new Random();

while(true) {

int flip = flippinCoin.nextInt(2) + 1;

if(flip==1){
System.out.println("Head");
h1++;
}else{
System.out.println("Tail");
t1++;
}
if(h1==1000){
break;
}
}
int total = t1+h1;
System.out.println("Head = "+h1+"\nTail = "+t1+"\nTimes = "+total);
}
}
මචන් බලපන් හරිද කියල.

Last edited by MihiCherub; 04-24-2012 at 12:02 PM. Reason: Total එක දාන්න අමතක උනා. ඔන්න දැනම
Reply With Quote
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Copyright © 2006 - 2011 ElaKiri™ Beta2.Evo vBulletin, vBa iBproArcade Subdreamer I-Magic MKv
Optimisation plugin by DBtech

Page generated in 0.02467 seconds with 10 queries