我似乎无法得到底部"我"链接到下面的for循环中的变量我哪里出错?我试图编辑它更改变量并将变量放在for循环上面所有我得到的是错误
我也在使用eclipse luna
import java.util.Scanner;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class AssignmentProgramming {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("Please enter a string");
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String data = reader.readLine();
char ch =(char) System.in.read();
int letters=0;
for(int i=0; i<data.length(); i++);
{
char c=data.charAt(i);//<-- This i here
if (c==ch);
{letters++;
}
}
System.out.println(letters);
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试学习如何由用户在控制台中创建指定数量的线程。没有太多可以帮助我的内容,并且希望详细描述如何创建动态数量的线程。我知道如何使用扫描仪将用户输入到程序中,但需要线程创建方面的帮助
我尝试使用这种方法,因为它对我来说最有意义(我是一个学习CS的非常业余的程序员):如何动态创建线程?
我的代码
封装线程;
public class morethreads {
public Runnable MyRunnable;
public void run() {
for (int i = 0; i<20; i++)
System.out.println("Hello from a thread!" + i);
}
public void main(String args[]) {
Thread[] hello = new Thread [10];//amount of threads
for(int b =0; b < hello.length; b++){
hello[b] = new Thread(MyRunnable);//<<this is the issue
hello[b].start();
}
}
}
Run Code Online (Sandbox Code Playgroud) 这计算了字符串的整个长度,例如我是一个男人= 7个字母和9个字符我只想要总字母数量
import java.util.Scanner;
public class AssignmentProgramming {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("Please enter a string");
String input = sc.nextLine();
System.out.println(input);
String str = input;
String[] myString = str.split(" ");
int length = str.length();
System.out.println(length);
}
}
Run Code Online (Sandbox Code Playgroud)