小编sun*_*sun的帖子

如何在Java中跳过一个块?

在给出的程序中,我必须确保如果两个连续的字符是相同的.我不应该增加变量的值(Count)...我试过"break;",但是这会让我跳出"for循环",这是非常适得其反的.如何跳过给定的部分仍然继续"for循环"?

目前我对"Hello // world"的输出是3.它应该是2('/'表示''(空格)).

import java.util.Scanner;
class CountWordsWithEmergency
{
    public static void main()
    {
        Scanner input = new Scanner(System.in);
        System.out.println("Please input the String");
        String inp = input.nextLine();
        System.out.println("thank you");
        int i = inp.length();
        int count = 1;
        for(int j=0;j<=i-1;j++) //This is the for loop I would like to stay in.
        {
            char check = inp.charAt(j);
            if(check==' ')
            {
                if((inp.charAt(j+1))==check) //This is the condition to prevent increase for
                                             //count variable.
                {
                    count = count; //This does not work and neither …
Run Code Online (Sandbox Code Playgroud)

java loops for-loop breakpoints

3
推荐指数
1
解决办法
1284
查看次数

标签 统计

breakpoints ×1

for-loop ×1

java ×1

loops ×1