java - Making loops in order to test values -
this question has answer here:
i need making loop looks @ each value 1 number-1. how test each value see if divisor of number, , if is, adding sum.
this have far:
public static void main(string[] args) { scanner input = new scanner (system.in); system.out.print("please enter positive integer: "); int n = input.nextint(); while (n < 0) { system.out.println(n + " not positive."); system.out.print("please enter positive integer: "); n = input.nextint(); } }
you can use starting block application:
package testers; import java.io.console; public class application { public static void main(string[] args) { console console = system.console(); if (console == null) { system.err.println("no console."); system.exit(1); } boolean keeprunning = true; while (keeprunning) { string name = console.readline("type positive integer"); try{ int integer = integer.parseint(name); if(integer < 0){ system.out.println("you must specify positive integer!"); } for(int = 1; i<integer; i++){ // our variable "i" smaller "integer". parse numbers between 1 , "integer" -1. if(i % 2 == 0){ //"i" divisible 2. of course, can change value want change to. //here can add sum }else{ //"i" not divisible 2. of course, can change value want change to. } } }catch(numberformatexception e){ system.out.println("you must specify positive integer!"); } } } }
Comments
Post a Comment