2番目のforループが実行されない理由がわかりません。コンパイルされますが、これを実行すると機能しません〜_〜
import java.util.Scanner;
public class ranges
{
public static void main (String[] args)
{
Scanner scan = new Scanner (System.in);
int size;
int input;
int count = 0;
int occurence = 0;
System.out.print ("Please enter the size of your array: ");
size = scan.nextInt();
int[] list = new int[size];
for (int index = 0 ; index < list.length ; index++)
{
System.out.print ("Please enter an integer between 0 to 50: ");
input = scan.nextInt();
if ( input >= 0 && input <= 50 )
{
list[index] = input;
}
else
{
System.out.println ("Invalid output, please try again");
index--;
}
}
int right = (list.length)-1;
int left = 0;
for (int counter = left ; counter < list.length ; counter++)
{
while ( right >= left )
{
if ( list[left] == list[right] )
{
occurence++;
right--;
}
}
right = (list.length)-1;
System.out.println ("The number " + list[left] + " was added " + occurence + "4 times");
}
for (int value : list)
{
System.out.print (value + " ");
}
;
}
}
発生を評価するための更新されたforループ
for(int left = 0; left <list.length; left ++)
{{
while ( right >= left )
{
if ( list[left] == list[right] )
{
occurence++;
}
right--;
}
System.out.println ("The number " + list[left] + " was added " + occurence + " times");
right = (list.length)-1;
occurence = 0;
}
私はそれを少しクリーンアップしました、そして今発生は入力と同じです