Home>
Enter your language here
Java while statement
Code
Since there is a problem that cannot be solved by studying java, I would appreciate a solution.
Problem description
↓
Declares a while statement that performs loop processing when the value of variable num is 100 or less.
In the processing of the while statement, add a numerical value to the variable num, and the value to be added adds the current loop count, and the first processing is +1
The second process is +2 The third process is +3 ... The variable value is displayed on the screen after the loop.
### Problems that occur
I'm in trouble because all five loop processing results are not displayed properly.
### Corresponding source code
import java.util.Scanner;
public class Main {
public static void main (String [] args) {
Scanner scan = new Scanner (System.in);
String text = scan.next ();
int num = Integer.parseInt (text);
int num1 = 0;
int num2 = 1;
while (num<= 100) {
num + = num1 + num2;
num ++;
}
System.out.println (num);
}
}
Please describe what you tried for the problem here.
I did some research on the internet, but I couldn't find a site to get clear tips.
Supplemental information (FW/tool version etc.)Please provide more detailed information here.
-
Answer # 1
Related articles
- regarding for or while statement [java]
- java - i have a question about a while statement
- java - about preparestatement of try-with-resources statement
- about if statement in java
- about java multidimensional array, for statement
- java sql update statement
- java calculation count and result
- java - about sql statement generation by doma
- java - i got an error while error merging dex archive in andoroid studio
- java - i don't understand the problem of double for statement with array
- php - (use the while statement to display the total value from 1 to 10000)
- with javascript, when you put an if statement in a while statement, it's good
- how to read if statement (in java
- java - how to use if statement with the value specified in servlet in jsp?
- about java for statement
- javascript - regarding the syntax of the while statement [a fairly basic question]
- java i want to store them in hashmap while dividing them by the same key
- about conditional branch of java if statement
- java for statement of an array that is assigned a random number
- java - update statement is used in dao, but it is not reflected
Related questions
- java : All birthdays must be returned
- csv - ruby game creation
- i want to add subtotal lines for each category when outputting csv in java
- java - i would like to know in the while and for statements that integers between 1 and 16 are displayed as common multiples of
- c - the while statement is not applied and ends without looping
- python - i shouldn't be out of the while loop, but it doesn't print
- php - how to loop with undecided number of times
- javascript - i can't get out of while
- java for loop character addition
What is the logic below?