有人可以解释以下功能的输出:
public static void main(String args[]) {
String str1 = new String("20");
String str2 = new String("100");
List<String> list = new ArrayList<>();
list.add(str1);
list.add(str2);
Collections.sort(list); // list is [100,20] now
}
Run Code Online (Sandbox Code Playgroud)
我希望排序工作在输入的ASCII值,即49为1,50为2,依此类推.
有人可以确认吗?
我有一个Menu类,其方法显示菜单,存储然后返回用户所做的选择.
public class Menu {
public static int menuSelect(){
Scanner input = new Scanner(System.in);
System.out.println("Hello, Please Select A Function: ");
System.out.println("1) Sort All Banks Alphabetically ");
System.out.println("2) Calculate Interest And Show Balance ");
System.out.println("3) Transfer Money ");
System.out.println("4) Exit ");
int Select = input.nextInt();
return Select;
}
}
Run Code Online (Sandbox Code Playgroud)
我想在我的main方法中使用返回值,但我不确定如何.我在主要方法中提出了一个对象:
Menu menuObject = new Menu();
Run Code Online (Sandbox Code Playgroud)
并添加:
Menu.menuSelect();
Run Code Online (Sandbox Code Playgroud)
我知道菜单运行但我希望从主类中的变量中返回选择返回值.任何帮助将非常感激.
谁能解释两种方法之间有什么区别?
方法1
public void run(){
run();
}
Run Code Online (Sandbox Code Playgroud)
方法2
public void run(){
while(true){
}
}
Run Code Online (Sandbox Code Playgroud) 我必须编写一个包含两个类的代码,一个反转字符串改变位置,例如
I love you 变 uoy evol I
而另一个类在不改变位置的情况下反转字符串,例如
I love you成为I evol uoy.
我有一个小代码,但是如果在这些类中调用方法,我就无法找到方法.
我现在拥有的只是以第一种方式反转字符串的代码.欢迎任何帮助.
class StringReverse2{
public static void main(String[] args){
String string="I love you";
String reverse = new StringBuffer(string). //The object created through StringBuffer is stored in the heap and therefore can be modified
reverse().toString(); //Here the string is reversed
System.out.println("Old String:"+string); //Prints out I love you
System.out.println("New String : "+reverse);//Prints out the reverse that is "uoy evol I"
}
}
Run Code Online (Sandbox Code Playgroud) 我可以访问并打印我的arraylist中的字符串
list.get(0).getLastName();
Run Code Online (Sandbox Code Playgroud)
但我无法访问char:
list.get(0).getLastName().charAt(0);
Run Code Online (Sandbox Code Playgroud)
即使我设置list.get(0).getLastName()等于像str这样的变量,我也可以打印str,但如果我尝试str.charAt(0),它永远不会返回任何我可以打印或使用的东西.
任何帮助赞赏.
我正在寻找一个命令,将bash中每行的第一个字母大写.
其实我用过这个命令:
sed 's/^\(.\)/\U\1/'
Run Code Online (Sandbox Code Playgroud)
但我需要使用另一个命令而不是"\ U"..
就目前而言,这是我正在尝试的代码:
if(gear.isLeftHand())
helix = (gear.getParentPair().beta());
else if (gear.isRightHand())
helix = Math.PI - (gear.getParentPair().beta());
else if (gear.isSpur())
helix = 0;
else
helix = 0;
double stepAng = (thickness /radius) * helix;
Run Code Online (Sandbox Code Playgroud)
但是它不起作用,这是因为'helix无法解析为变量'
我试图获得stepAng的值,这取决于初始角度是左手还是右手,因此"螺旋"的值将根据此方向根据不同的公式计算.
非常感激任何的帮助.
我创建一个类Course代表有三个属性的课程对象courseID,letterGrade和numberGrade.
numberGrade是letterGrade使用该computeGrade()方法计算的.我正在测试我的Course课程并发现使用的switch语句computeGrade无法识别相关内容substring.
为什么会这样?
public void computeGrade() {
switch (letterGrade.substring(0,1)) {
case "A": numberGrade = 4.0;
case "B": numberGrade = 3.0;
case "C": numberGrade = 2.0;
case "D": numberGrade = 1.0;
case "F": numberGrade = 0.0;
default: numberGrade = 999;
}
if(letterGrade.endsWith("+") && !letterGrade.startsWith("A") && !letterGrade.startsWith("F")) {
numberGrade += 0.3;
}
else if(letterGrade.endsWith("-") && !letterGrade.startsWith("D") && !letterGrade.startsWith("F")) {
numberGrade -= 0.3;
} …Run Code Online (Sandbox Code Playgroud) 我收到了以下错误
请妥善解决此问题.
Map approvers1 = new HashMap<String, AdaptApproverObject>();
List<String> approverObjectTids = new ArrayList<String>();
Run Code Online (Sandbox Code Playgroud)