import java.util.Scanner;
public class FloydTriangle {
public static void main(String[] args){
int range, i, j, k=1;
Scanner scan = new Scanner(System.in);
System.out.println("Enter the num of rows: ");
range=scan.nextInt();
System.out.println("Floyd's Triangle :n");
for(i=1; i<=range; i++)
{
for(j=1, j<=i; j++; k++)
{
System.out.println(k + " ");
}
System.out.println();
}
}
}
Следующий код при компиляции выдает ошибку: Error:(15, 23) java: not a statement в этой строке: for(j=1, j<=i; j++; k++)
задан 5 фев 2018 в 19:17
1
Первый for написали правильно, а второй нет. Вместо , нужно ;.
for(j=1; j<=i; j++, k++)
{
System.out.println(k + " ");
}
ответ дан 5 фев 2018 в 19:21
![]()
TsyklopTsyklop
3,8354 золотых знака22 серебряных знака52 бронзовых знака
2
public class Hello
{
public static void main(String args[])
{
int i = 1;
for(i; ;i++ )
{
System.out.println(i);
}
}
}
I would like to understand why above code is giving error as:
not a statement for(i ; ; i++)
dbush
199k21 gold badges210 silver badges262 bronze badges
asked Feb 18, 2015 at 15:31
3
Because the raw i in the first position of your for is not a statement. You can declare and initialize variables in a for loop in Java. So, I think you wanted something like
// int i = 1;
for(int i = 1; ;i++ )
{
System.out.println(i);
}
If you need to access i after your loop you could also use
int i;
for(i = 1; ; i++)
{
System.out.println(i);
}
Or even
int i = 1;
for(; ; i++)
{
System.out.println(i);
}
This is covered by JLS-14.4. The for Statement which says (in part)
A for statement is executed by first executing the ForInit code:
If the ForInit code is a list of statement expressions (§14.8), the expressions are evaluated in sequence from left to right; their values, if any, are discarded.
answered Feb 18, 2015 at 15:37
![]()
Elliott FrischElliott Frisch
195k20 gold badges156 silver badges245 bronze badges
The lone i at the start of the for statement doesn’t make any sense — it’s not a statement. Typically the variable of the for loop is initialized in the for statement as such:
for(int i = 1;; i++) {
System.out.println(i);
}
This will loop forever though, as there is no test to break out of the for loop.
answered Feb 18, 2015 at 15:42
Change your for loop to:
for(; ;i++ )
It will loop infinitely printing i. Your i is not of boolean type which you could have place in condition of for loop and for loop has format like:
for (init statement; condition; post looping)
So in your init statement you just had i which is not a valid statement and hence you get error from compiler.
answered Feb 18, 2015 at 15:34
![]()
SMASMA
35.9k8 gold badges47 silver badges73 bronze badges
public class Hello
{
public static void main(String args[])
{
int i = 1;
for(i; ;i++ )
{
System.out.println(i);
}
}
}
I would like to understand why above code is giving error as:
not a statement for(i ; ; i++)
dbush
199k21 gold badges210 silver badges262 bronze badges
asked Feb 18, 2015 at 15:31
3
Because the raw i in the first position of your for is not a statement. You can declare and initialize variables in a for loop in Java. So, I think you wanted something like
// int i = 1;
for(int i = 1; ;i++ )
{
System.out.println(i);
}
If you need to access i after your loop you could also use
int i;
for(i = 1; ; i++)
{
System.out.println(i);
}
Or even
int i = 1;
for(; ; i++)
{
System.out.println(i);
}
This is covered by JLS-14.4. The for Statement which says (in part)
A for statement is executed by first executing the ForInit code:
If the ForInit code is a list of statement expressions (§14.8), the expressions are evaluated in sequence from left to right; their values, if any, are discarded.
answered Feb 18, 2015 at 15:37
![]()
Elliott FrischElliott Frisch
195k20 gold badges156 silver badges245 bronze badges
The lone i at the start of the for statement doesn’t make any sense — it’s not a statement. Typically the variable of the for loop is initialized in the for statement as such:
for(int i = 1;; i++) {
System.out.println(i);
}
This will loop forever though, as there is no test to break out of the for loop.
answered Feb 18, 2015 at 15:42
Change your for loop to:
for(; ;i++ )
It will loop infinitely printing i. Your i is not of boolean type which you could have place in condition of for loop and for loop has format like:
for (init statement; condition; post looping)
So in your init statement you just had i which is not a valid statement and hence you get error from compiler.
answered Feb 18, 2015 at 15:34
![]()
SMASMA
35.9k8 gold badges47 silver badges73 bronze badges
Регистрация на форуме тут, о проблемах пишите сюда — alarforum@yandex.ru, проверяйте папку спам! Обязательно пройдите восстановить пароль
| Поиск по форуму |
| Расширенный поиск |

int a, b, c, d, x = 4572;
a = x / 1000;
b = x % 1000 / 100;
c = x % 100 / 10;
d = x % 10;
System.out.println(x/(d+b));
> else
System.out.println(x/(c+a));
тут еще нужно ввести, что d+b не равно 0
d+b!=0
где это написать и как правильно написать, чтобы не выскакивал ошибка not a statement
thank you
| Serge_Bliznykov |
| Посмотреть профиль |
| Найти ещё сообщения от Serge_Bliznykov |

Интенсив по Python: Работа с API и фреймворками 24-26 ИЮНЯ 2022. Знаете Python, но хотите расширить свои навыки?
Slurm подготовили для вас особенный продукт! Оставить заявку по ссылке — https://slurm.club/3MeqNEk
Understanding Common Errors In Java

When we were building our automated common error feedback feature on Mimir Classroom, we analyzed millions of stack traces that our students received when completing their coursework on our platform. In this post, you will find the errors we found to be most troubling to students in Java and some tips on how to approach them.
To start off, here is a quick refresher on how to read an error in the Java stack trace.

1. ’;’ expected
This error means that you forgot a semicolon in your code. If you look at the full error statement, it will tell you where in your code you should check within a few lines. Remember that all statements in Java must end in a semicolon and elements of Java like loops and conditionals are not considered statements.
2. cannot find symbol
This error means that Java is unable to find an identifier that it is trying to work with. It is most often caused by the following:
- You misspelled a variable name, class name, or a keyword somewhere. Remember that Java is case sensitive.
- You are trying to access a variable or class which does not exist or can not be accessed.
- You forgot to import the right class.
3. illegal start of expression
This error usually occurs when your code does not follow Java’s standard structure. Check the nesting of your variables and ensure that all your and ( ) are in the right place..
4. class, interface, or enum expected
This error is usually caused by misplaced . All code in Java needs to be contained within a class, interface, or enum. Ensure that all of your code is within the of one of those. We often have seen this error when there is an extra > at the end of your code.
5. reached end of file while parsing
This error usually occurs when you are missing a > somewhere in your code. Ensure that for every in the right place.
6. missing return statement
This error usually means one of two things:
- Your method is expecting a return statement but is missing one. Ensure that if you declared a method that returns something other than void and that it returns the proper variable type.
- Your return statements are inside conditionals who’s parameters may not be reached. In this case, you will need to add an additional return statement or modify your conditionals.
7. ‘else’ without ‘if’
This error means that Java is unable to find an if statement associated to your else statement. Else statements do not work unless they are associated with an if statement. Ensure that you have an if statement and that your else statement isn’t nested within your if statement.
8. ‘(‘ expected or ‘)’ expected
This error means that you forgot a left or right parenthesis in your code. If you look at the full error statement, it will tell you where in your code you should check. Remember that for every ( you need one ).
9. case, default, or ‘>’ expected
This error means that your switch statement isn’t properly structured. Ensure that your switch statement contains a variable like this: switch (variable). Also ensure that every case is followed by a colon (:) before defining your case.
10. ‘.class’ expected
This error usually means that you are trying to declare or specify a variable type inside of return statement or inside of a method calls. For example: “return int 7;» should be «return 7;»
11. invalid method declaration; return type required
Every Java method requires that you declare what you return even if it is nothing. «public getNothing()» and «public static getNumber()» are both incorrect ways to declare a method.
The correct way to declare these is the following: «public void getNothing()» and «public static int getNumber()»
12. unclosed character literal
This error occurs when you start a character with a single quote mark but don’t close with a single quote mark.
13. unclosed string literal
This error occurs when you start a string with a quotation mark but don’t close with a second quotation mark. This error can also occur when quotation marks inside strings are not escaped with a backslash.
14. incompatible types
This error occurs when you use the wrong variable type in an expression. A very common example of this is sending a method an integer when it is expecting a string. To solve this issue, check the types of your variables and how they are interacting with other types. There are also ways to convert variable types.
15. missing method body
This error commonly occurs when you have a semicolon on your method declaration line. For example «public static void main(String args[]);». You should not have a semicolon there. Ensure that your methods have a body.
16. unreachable statement
This error means that you have code that will never be executed. Usually, this is after a break or a return statement.
Types of Errors in Java with Examples
Error is an illegal operation performed by the user which results in the abnormal working of the program. Programming errors often remain undetected until the program is compiled or executed. Some of the errors inhibit the program from getting compiled or executed. Thus errors should be removed before compiling and executing.
The most common errors can be broadly classified as follows:
1. Run Time Error:
Run Time errors occur or we can say, are detected during the execution of the program. Sometimes these are discovered when the user enters an invalid data or data which is not relevant. Runtime errors occur when a program does not contain any syntax errors but asks the computer to do something that the computer is unable to reliably do. During compilation, the compiler has no technique to detect these kinds of errors. It is the JVM (Java Virtual Machine) that detects it while the program is running. To handle the error during the run time we can put our error code inside the try block and catch the error inside the catch block.
For example: if the user inputs a data of string format when the computer is expecting an integer, there will be a runtime error. Example 1: Runtime Error caused by dividing by zero
нот а стэйтмент
com/javarush/task/task06/task0606/Solution.java:16: error: not a statement
for (int x = integer.parseInt(reader.readLine()); x/10!=0; x/10 )
Не нравится валидатору x/10
Что не так?
package com.javarush.task.task06.task0606;
import java.io.*;
/*
Чётные и нечётные циферки
*/
public class Solution {
public static int even;
public static int odd;
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); //напишите тут ваш код
for (int x = integer.parseInt(reader.readLine()); x/10!=0; x/10 )
{
if (x%2=0)
even++;
else
odd++;
}
System.out.println(«Even: «+even+» Odd: «+odd);
}
}
Этот веб-сайт использует данные cookie, чтобы настроить персонально под вас работу сервиса. Используя веб-сайт, вы даете согласие на применение данных cookie. Больше подробностей — в нашем Пользовательском соглашении.
|
Hayko985985 0 / 0 / 0 Регистрация: 11.07.2017 Сообщений: 2 |
||||
|
1 |
||||
|
11.07.2017, 20:26. Показов 8017. Ответов 2 Метки нет (Все метки)
тут еще нужно ввести, что d+b не равно 0
__________________
0 |
|
Psyh 13 / 9 / 10 Регистрация: 03.06.2016 Сообщений: 50 |
||||
|
12.07.2017, 19:00 |
2 |
|||
|
Hayko985985, если я правильно понял, то ты хочешь добавить в условие x < 5000 , d+b != 0
0 |
|
2402 / 1861 / 472 Регистрация: 17.02.2014 Сообщений: 9,028 |
|
|
14.07.2017, 11:25 |
3 |
|
Hayko985985, А при каких значениях х у вас возникает ошибка?
0 |
Содержание
- 5 ответов
- 1 ответ 1
- Всё ещё ищете ответ? Посмотрите другие вопросы с метками java или задайте свой вопрос.
- Похожие
0 Danae [2015-02-25 09:50:00]
Мне нужно, чтобы пользователь вводил начальный номер, конечный номер и приращение. Я, наверное, сделал это ужасно неправильно, но это было поздно, и я полностью потерялся. Это говорит мне, что мой for-loop – это «не утверждение».
java loops for-loop netbeans user-input
5 ответов
У вас есть 2 вопроса:
Измените цикл for на:
for (int count = start; count > >
Здесь вам не нужен блок кода
public static vo >
используйте круглую скобку для цикла в следующем порядке
Вам нужно назначить приращение для подсчета в цикле for
Ты должен попытаться
Компонент приращения оператора for должен быть либо корректным, либо пустым. count+(inc) – не действительный оператор. count=count+(inc) будет действительным утверждением.
Учебное пособие по JavaSE хорошо объясняет инструкцию for: For for Statement
Следующий код при компиляции выдает ошибку: Error:(15, 23) java: not a statement в этой строке: for(j=1, j | улучшить этот вопрос
1 ответ 1
Первый for написали правильно, а второй нет. Вместо , нужно ; .

Всё ещё ищете ответ? Посмотрите другие вопросы с метками java или задайте свой вопрос.
Похожие
Для подписки на ленту скопируйте и вставьте эту ссылку в вашу программу для чтения RSS.
дизайн сайта / логотип © 2020 Stack Exchange Inc; пользовательское содержимое попадает под действие лицензии cc by-sa 4.0 с указанием ссылки на источник. rev 2020.1.14.35771
I’m new to java and I’m having some trouble. I keep getting two errors on this, Not a statement and «;» expected.
Also if there is other stuff wrong please let me know. =D
This is the part with the error int for(int i=0; i >= 8; i++)
here is the whole thing
public class CurranThomasProg5
public static void main(String args[])
System.out.println(«Enter a password that meets the following rules:»);
System.out.println(«Is at least 8 characters long.»);
System.out.println(«Contains atleast 1 lower letter character «);
System.out.println(«Contains atleast 1 upper letter character «);
System.out.println(«Contains atleast 1 numeric digit»);
System.out.println(«Contains atleast 1 special character from the set: !@#$%^&*»);
System.out.println(«Does not contain the word «and» or the word «end»»);
String pw = input.nextLine();
boolean oneLower = false; boolean oneUpper = false;
boolean oneNumber = false;
boolean oneSpecial = false;
boolean noAnd = false;
boolean noEnd = false;
int for(int i=0; i >= 8; i++)
char c = pw.charAt(i);
if(Character.isLowerCase(c)) oneLower = true;
if(Character.isUpperCase(c)) oneUpper = true;
if(Character.isDigit(c)) oneNumber = true;
if (pw.indexOf(«and») > 0) noAnd = true;
if (pw.indexOf(«end») > 0) noEnd = true;
if(oneLower && oneUpper && oneNumber && oneSpecial && noAnd && noEnd && length)