java - How do I display what system.out.println() shows in the console, in an Android Application's activity? -
for example, have simple coin flip program display single line of text. after running program java project, console display "there 473 heads , 527 tails." don't mean displaying in logcat, displaying when using application.
//basic coin flip statistics program. package com.company.practice; import java.util.random; public class coinflip { public static void main(string[] args){ system.out.println("toss coin 1000 times"); int heads = 0; int tails = 0; random r = new random(); for(int flips = 0; flips < 1000; flips++){ //change # after < set amount of flips. int side = r.nextint(2); if(side == 0) heads++; else tails++; } system.out.println("there " + heads + " heads , " + tails + " tails."); } }
how display line of code @ bottom says, "system.out.println(...)" text in android application's activity?
you'd display in ui attached activity.
an android app not constructed same java program. there's no "main" class. in fact, don't declare application subclass. instead, construct loose web of activities interact each other using intents. each activity has associated layout contains views. when activity starts up, load main layout, store view objects in variables in activity. when want modify contents of view, call method (often settext()) change contents.
layouts , views can defined in xml file, or set programmatically.
those of have written java programs before have step some, , approach app construction different point of view. encourage browse through documentation, particularly training class, , @ samples.
Comments
Post a Comment