+ 10

I want to take a no. from user and wants to print the increment sequence until it reaches (no. *100) using while,dowhile & for?

Loops

13th Jun 2017, 3:48 AM
Pulkit sharma
Pulkit sharma - avatar
7 odpowiedzi
+ 1
hey sorry. it won't work cause you need to keep the x you multiply for 100 constant in the while. so create a variable int before the while and assign it the value of x. then change the second x in the condition for the other variable. int z = x; while (x <=(z*100)){ System.out.println (x); x++; } it will surely work now
13th Jun 2017, 4:35 AM
Daniel Leonard
Daniel Leonard - avatar
+ 10
import java.util.Scanner; public class Program { public static void main(String[] args) { int x; Scanner scn = new Scanner(System.in); x = scn.nextInt(); System.out.println("your entered number: "+ x); System.out.println("increment sequence " + x + " is "); while(x<x*100) { System.out.println (x++); } } } Why this code is not giving the desired output?
13th Jun 2017, 3:58 AM
Pulkit sharma
Pulkit sharma - avatar
+ 8
I want to print the no until (x multiply 100)
13th Jun 2017, 4:16 AM
Pulkit sharma
Pulkit sharma - avatar
+ 2
int counter = [input from user]; while(counter <= 100) System.out.println(counter++); }
13th Jun 2017, 3:55 AM
Ajay Gonzalez
Ajay Gonzalez - avatar
+ 2
int count= [input]; do{ System.out.println("" + count); count++; }while(count<100); System.out.println("count");
13th Jun 2017, 3:59 AM
Tarcisio Almeida
+ 1
if you want to increment the value the user enters until it reaches 100 you need to change the condition like this (x <=100) Also you need to put the x++ outside the println cause in the way you put it the variable x is not incrementing, just increments the print by one. After the println put x++; import java.util.Scanner; public class Program { public static void main(String[] args) { int x; Scanner scn = new Scanner(System.in); x = scn.nextInt(); System.out.println("your entered number: "+ x); System.out.println("increment sequence " + x + " is "); while(x<=100) { System.out.println (x); x++; } } } Like this
13th Jun 2017, 4:11 AM
Daniel Leonard
Daniel Leonard - avatar
0
if it is until the number multiplied for 100 just put the condition like this (x <= (x*100)) and remember to put the increment outside the println
13th Jun 2017, 4:18 AM
Daniel Leonard
Daniel Leonard - avatar