这是我现在的程序:
import java.util.Scanner;
public class SelfAssessment
{
public static void main(int num, int counter, String str)
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number:");
num = sc.nextInt();
SelfAssessment.function1(num);
SelfAssessment.function2(str);
}
//Collatz function
public static int function1(int num) (Collatz conjecture)
{
if(num < 1)
{
return -1;
}
else if(num >= 1)
{
while(num>=1)
{
if(num%2 == 1)
{
num = (num*3)+1;
System.out.println(num);
}
else if(num%2 == 0 && num != 1)
{
num = num/2;
System.out.println(num);
}
}
}
return num;
}
public static int function2(String str) (method to count up the lower-case e's and upper-case d's in a string)
{
System.out.println("Enter a string:");
str = in.NextLine();
char ch;
int lowereCount;
int upperDCount;
if(ch = 'e')
{
lowereCount++;
}
else if(ch='D')
{
upperDCount++;
}
}
public static int function3(int arr[], int findNum, int arraySize) (method to search for a certain character and return it (if found)
{
System.out.println("Enter numbers into array:");
Scanner sc = new Scanner(System.in);
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
for(int x=0; x<2; i++)
{
arraySize = Integer.parseInt(br.readLine());
}
for(int i=0; i<arraySize;i++)
{
arr[i] = sc.nextInt();
}
for (int i = 0; i<arr.length; i++)
{
if(arr[i] == findNum)
{
return i;
}
else if(arr[i] == findNum)
{
return -1;
}
}
}
}
我现在遇到的问题(至少是我能想到的问题)如下:
- 尝试运行它时,它说它找不到类
SelfAssessment
- 在方法
function3
中,它说它找不到InputStreamReader
并且BufferedStreamReader
我知道还有更多错误,但我现在无法考虑它们。
有人也可以检查我的代码,看看是否还有其他错误?