Java 安卓工作室';类别';或';接口';预期
我已经用Java编写了一些创建随机句子的代码。它可以在一个在线Java编译器上运行,尽管我似乎无法在Android Studio上运行它。这是我的密码:Java 安卓工作室';类别';或';接口';预期,java,android,Java,Android,我已经用Java编写了一些创建随机句子的代码。它可以在一个在线Java编译器上运行,尽管我似乎无法在Android Studio上运行它。这是我的密码: package com.tech.littlest.myapplication; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import java.util.Random; public class Activity2 extends
package com.tech.littlest.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import java.util.Random;
public class Activity2 extends AppCompatActivity {
final static int NO_DEDICATED_ARRAYS = 12; // This number is equal to the number of arrays in a string NOTE: This number MUST be constant across all strings
final static int NO_OUTPUT_SENTENCES = 1; // How many sentences generated and displayed for the user
final static String SPACER = " "; // Inputs a " " character (Space) into the display
final static String PERIOD = ".";
static Random r = new Random();
public static void main( String args[] ){
String proposition_user[] = { "You should build and invention that", "You should build a robot that", "You should create a whatchamacallit that", "There should be a device that", "Create a futuristic thing that", "Make a thing that", "Make something cool that", "I don't recall there being a thing that", "Create a sick thing that", "Devise a plan to create an object that", "I want a thing that", "If I just had an thingamajig that", "Create a thingimajig that"};
String plural_noun[] = { "children", "chickens", "the ocean", "cars", "apples", "houses", "water", "buildings", "people", "your friends", "farms", "the human race" };
String verb[] = { "directs you to", "drives on", "manages", "develops", "makes","eats", "helps", "relocates", "fixes", "feeds", "runs on", "washes" };
String sentence;
for (int i = 0; i < NO_OUTPUT_SENTENCES; i++){
sentence = proposition_user[rand()];
char c = sentence.charAt(0);
sentence = sentence.replace( c, Character.toUpperCase(c) );
sentence += SPACER;
sentence += (verb[rand()]);
sentence += (SPACER + plural_noun[rand()]);
sentence += PERIOD;
sentence += "";
System.out.println(sentence);
}
}
static int rand(){
int ri = r.nextInt() % NO_DEDICATED_ARRAYS;
if ( ri < 0 )
ri += NO_DEDICATED_ARRAYS;
return ri;
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_2);
}
}
package com.tech.littlest.myapplication;
导入android.support.v7.app.AppActivity;
导入android.os.Bundle;
导入java.util.Random;
公共类活动2扩展了AppCompatActivity{
final static int NO_DEDICATED_array=12;//此数字等于字符串中的数组数注意:此数字在所有字符串中都必须是常量
final static int NO_OUTPUT_stations=1;//为用户生成并显示了多少个句子
final static String SPACER=“;//将“”字符(空格)输入显示器
最终静态字符串周期=“.”;
静态随机r=新随机();
公共静态void main(字符串参数[]){
String proposition_user[]={“你应该建造和发明那个”,“你应该建造一个机器人”,“你应该创造一个什么叫做什么”,“应该有一个设备”,“创造一个未来的东西”,“制造一个东西”,“制造一个很酷的东西”,“我不记得有什么东西”,“制造一个恶心的东西”,“设计一个计划来创造一个对象”,“我想要一个东西”,“如果我有一个东西”,“创造一个东西”};
字符串复数名词[]={“儿童”、“鸡”、“海洋”、“汽车”、“苹果”、“房子”、“水”、“建筑物”、“人”、“你的朋友”、“农场”、“人类”};
字符串动词[]={“指示您”、“继续驾驶”、“管理”、“开发”、“制造”、“吃”、“帮助”、“重新定位”、“修复”、“馈送”、“继续运行”、“清洗”};
串句;
for(int i=0;i
我在第37行得到一个“class”或“interface”预期错误。第三个括号。谢谢。您应该删除
静态int rand()函数之后的额外
您应该删除静态int rand()之后的额外
功能删除第37行的}
它关闭公共类活动2扩展AppCompatActivity{
(第7行),而下面仍然有代码。删除第37行的}
它关闭公共类活动2 extends-AppCompatActivity{
(第7行),而下面仍然有代码