当我尝试:
Queue<Integer> q = new Queue<Integer>();
Run Code Online (Sandbox Code Playgroud)
编译器给我一个错误.有帮助吗?
另外,如果我想初始化队列,我是否必须实现队列的方法?
如果我们在for循环中有一个if语句,它会停止循环或if条件......
例:
for (int i = 0; i < array.length; i++) {
if (condition) {
statement;
break;
}
}
Run Code Online (Sandbox Code Playgroud) Scanner scan = new Scanner(System.in);
double numbers = scan.nextDouble();
double[] avg =..????
Run Code Online (Sandbox Code Playgroud) import java.util.Scanner;
public class Test
{
public static void main(String[] args)
{
char[] sArray;
Scanner scan = new Scanner(System.in);
System.out.print("Enter a Palindrome : ");
String s = scan.nextLine();
sArray = new char[s.length()];
for(int i = 0; i < s.length(); i++)
{
s.toLowerCase();
sArray[i] = s.charAt(i);
System.out.print(sArray[i]);
}
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试计算学生成绩的平均值:
import java.util.Scanner;
public class Average
{
public static void main(String[] args)
{
int mark;
int countTotal = 0; // to count the number of entered marks
int avg = 0; // to calculate the total average
Scanner Scan = new Scanner(System.in);
System.out.print("Enter your marks: ");
String Name = Scan.next();
while (Scan.hasNextInt())
{
mark = Scan.nextInt();
countTotal++;
avg = avg + ((mark - avg) / countTotal);
}
System.out.print( Name + " " + avg );
}
}
Run Code Online (Sandbox Code Playgroud) 我使用以下循环,但它只输入第一个字符,其余为数字,任何想法?
import java.awt.*;
import javax.swing.KeyStroke;
public class test {
public static void main(String[] args) throws AWTException
{
Robot r = new Robot();
String s = "Face";
for (int i = 0; i < s.length(); i++)
{
char res = s.charAt(i);
r.keyPress(res);
r.keyRelease(res);
r.delay(1000);
}
}
}
Run Code Online (Sandbox Code Playgroud)
输出输入:F135
Integer[] ints = list.toArray(new Integer[]{});
Run Code Online (Sandbox Code Playgroud)
如果我删除" {}",编译器会要求填充数组的维度.这两个括号作为命令意味着什么?
import java.util.*;
public class Test
{
static List<Integer> list = new LinkedList<Integer>();
public static void main(String[] args)
{
Scanner scanOne = new Scanner(System.in);
System.out.println("Enter integers to be added to the list with a space between every number : ");
String name = scanOne.next();
Scanner scanTwo = new Scanner(scanOne.nextLine());
while (scanTwo.hasNextInt())
{
list.add(scanTwo.nextInt());
}
print();
}
public static void print()
{
ListIterator<Integer> listIT = list.listIterator(); // using the list Interface's method "listIterator()" to Iterate through the listIT
while(listIT.hasNext())
{
int n …Run Code Online (Sandbox Code Playgroud) 我将一个对象数组从我已经创建的学生类复制到链接列表,但在第5行,显示以下错误:("找不到符号 - E类")
这是为什么?
import java.util.*;
public class StudentLinkedList
{
private List<E[]> studentLL = new LinkedList<E[]>();
public StudentLinkedList(Student[] st)
{
for(int i = 0; i < st.length; i++)
{
studentLL.add(st[i]);
}
}
}
Run Code Online (Sandbox Code Playgroud) import java.util.Scanner;
import java.lang.String;
public class SA3
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
System.out.print("Enter student record : ");
String scores = scan.nextLine();
String[] StringOfMarks = scores.split(",");
double[] Marks = new double[StringOfMarks.length];
for(double i = 0; i < StringOfMarks.length; i++)
{
Marks[i] = StringOfMarks[i];
}
}
}
Run Code Online (Sandbox Code Playgroud)