如何获取字符串的最后一个字符?
public class Main
{
public static void main(String[] args)
{
String s = "test string";
//char lastChar = ???
}
}
Run Code Online (Sandbox Code Playgroud) 我刚刚重新格式化了我的电脑.我有windows xp sp3 32位.我安装java jdk android sdk eclipse ide
当我去创建一个新的android项目时,我得到了这个错误.
Project'HelloAndroid2'缺少必需的源文件夹:'gen'
请帮助我是eclipse的新手,所以给出详细的回复.
如何阻止条件循环运行.例如,如果我编写一个if接受0到100之间值的语句.如果用户输入的数字小于0或大于100,如何停止程序.
import java.util.Scanner;
public class TestScores {
public static void main(String[]args) {
int numTests = 0;
double[] grade = new double[numTests];
double totGrades = 0;
double average;
Scanner keyboard = new Scanner(System.in);
System.out.print("How many tests do you have? ");
numTests = keyboard.nextInt();
grade = new double[(int) numTests];
for (int index = 0; index < grade.length; index++) {
System.out.print("Enter grade for Test " + (index + 1) + ": ");
grade[index] = keyboard.nextDouble();
if (grade[index] < 0 || grade[index]> …Run Code Online (Sandbox Code Playgroud) 这是我得到的错误:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
TeamLeader cannot be resolved to a type
at TeamLeadDemo.main(TeamLeadDemo.java:26)
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
import java.util.Scanner;
public class Employee {
public String empName, empNumber, hireDate;
public class TeamLeadDemo {}
public Employee(String empName, String empNumber, String hireDate) {
this.setEmpName(empName);
this.setEmpNumber(empNumber);
this.setHireDate(hireDate);
}
public void setEmpName(String empName) {
this.empName = empName;
}
public void setEmpNumber(String empNumber) {
this.empNumber = empNumber;
}
public void setHireDate(String hireDate) {
this.hireDate = hireDate;
}
public String getEmpName() {
return empName;
} …Run Code Online (Sandbox Code Playgroud) 我是Java新手并制作Android应用程序.你如何根据用户输入的内容制作一个滚动大量骰子的Java程序?
我创建的Java程序只掷一个骰子.
你如何让Java从一到六随机滚动?
你如何让Java根据用户想要的次数制作随机数?
最后,如何让Java根据用户输入的数字绘制图像?
这是我的应用程序的样子.
有效的XHTML http://img852.imageshack.us/img852/4439/screenshotjavawarhammer.png.
这是我的代码
package com.warhammerdicerrolleralpha;
import java.util.Random;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class myMain extends Activity
{
/** Called when the activity is first created.
* @return */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Random myRandom = new Random(6);
Button buttonGenerate = (Button)findViewById(R.id.button1);
final TextView textGenerateNumber = (TextView)findViewById(R.id.text4);
buttonGenerate.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
// TODO Auto-generated …Run Code Online (Sandbox Code Playgroud) 我想返回我的数组的值加上递归调用的返回值.
但是由于某些原因,java不希望在构造函数之后拥有方法名称.
另外,当我试图将方法转换为另一种方法时,我使用isPalindrome时会出错.
我改变了我的程序,但我仍然遇到错误.
public class isPalindrome
{
/**
* This is the main entry point for the application
* @return
*/
public static boolean main(String[] args)
{
String[] word = {"KayaK", "Desserts, I stressed"};
boolean isPalindrome(String[] array, String s, String i)
{
if(i.charAt(0) == s.charAt(0))
{
System.out.println("You entered a Palindrome");
return true;
}
else
{
System.out.println("You didn't entered a Palindrome");
}
}
try
{
System.in.read();
}
catch (Throwable t)
{
}
}
Run Code Online (Sandbox Code Playgroud)
}
我对Java非常缺乏经验,我花了90%的时间来修复程序中的错误.此外,当我遇到语法错误时,我发现它们并修复它们是非常困难的.如果有经验的程序员可以提供一些交易提示,我将非常感激.我的类型错误的一个示例是令牌"void",@ expected上的语法错误.在public void employeeName()上.
import java.util.Scanner;
public class EmployeeDriver {
String employeeName;
public void employeeName() {
try {
Scanner scannerName = new Scanner(System.in);
System.out.println("Employye Name " + scannerName.nextLine());
System.out.println("When did you hire the Employee");
Scanner scanner1 = new Scanner(System.in);
System.out.println("The Employee name is " + scanner1.nextLine());
System.out.println("What is the Employee's Number");
Scanner scannerNum = new Scanner(System.in);
System.out.println("The Employee name is " + scannerNum.nextLine());
}catch (Exception e){
System.out.println("Error occurred" + e.getMessage());
}
}
public static void main(String[] args) { …Run Code Online (Sandbox Code Playgroud) 我有两个奇怪的错误
新错误是当我告诉java绘制一个显示x和y坐标的字符串时,它不会.
public void paint (Graphics g)
{
super.paint (g);
//System.out.println ("Boolean: " + this.closeDoors);
g.drawString("("+x+","+y+")",x,y);
}
Run Code Online (Sandbox Code Playgroud)
如果要编译它,请链接到我的程序. http://hotfile.com/dl/107032853/c81d927/Pigment.java.html
这是我的完整计划
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import java.awt.Graphics;
/**
*
* @author George Beazer
*/
public class Pigment extends JApplet
{
boolean closeDoors;
private int x = 0;
private int y = 0;
public static void main(String [] args) …Run Code Online (Sandbox Code Playgroud)