+ 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
7 Réponses
+ 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
+ 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?
+ 8
I want to print the no until (x multiply 100)
+ 2
int counter = [input from user];
while(counter <= 100)
System.out.println(counter++);
}
+ 2
int count= [input];
do{
System.out.println("" + count);
count++;
}while(count<100);
System.out.println("count");
+ 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
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