loops - how to write java program that read 5 numbers and calculate how many numbers has value from 0-9 -
loops - how to write java program that read 5 numbers and calculate how many numbers has value from 0-9 -
import java.util.scanner; public class { public static void main(string[] args) { scanner variable = new scanner(system.in); int = 0, counter = 0, n = 0; (i = 0; < 5; i++) { n = variable.nextint(); } if ((0 <= n) && (n <= 9)) { counter++; } system.out.println("the number of values enterd 0-9 " + counter); } }
i have no errors in programme i'm not getting right answer. illustration :
----jgrasp exec: java 5 6 4 number of values enterd 0-9 0 ----jgrasp: operation complete.
i shoud "3" "0"
your code doesn't work because missing brackets on loop. execute n=variable.nextint()
5 times without checking it, , check it. if include brackets should work.
java loops
Comments
Post a Comment