它给我一个错误信息说
PrintStream类型中的printf(String,Object ...)方法不适用于参数(String,void)
public class project {
public static void main(String[] args){
duo duoObject = new duo();
duo duoObject1 = new duo(5);
duo duoObject2 = new duo(2,6);
duo duoObject3 = new duo(3,7,5);
System.out.printf("%s\n", duoObject.militaryTime());
System.out.printf("%s\n", duoObject1.militaryTime());
System.out.printf("%s\n", duoObject2.militaryTime());
System.out.printf("%s\n", duoObject3.militaryTime());
}
}
public class duo {
private int hour;
private int minute;
private int second;
public duo(){
}
public duo(int h){
setHour(h);
}
public duo(int h, int m){
setHour(h);
setHour(m);
}
public duo(int h, int m, int s){
setHour(h); …Run Code Online (Sandbox Code Playgroud) Employee.java
class Employee implements Comparable
{
int id; String name; int age;
Employee(int id,String name,int age)
{
this.id=id;
this.name=name;
this.age=age;
}
public int compareTo(Object obj)
{
Employee emp = (Employee)obj;
if(age==emp.age)
{
return 0;
}
//else if(age>emp.age)
//return 1;
else
return -1;
}
}
Run Code Online (Sandbox Code Playgroud)
display_logic.java
import java.util.*;
class display_logic
{
public static void main(String args[])
{
ArrayList al = new ArrayList();
al.add(new Employee(1,"Supreeth",21));
al.add(new Employee(2,"Vijay",31));
al.add(new Employee(3,"Ganesh",21));
al.add(new Employee(4,"Aisu",31));
al.add(new Employee(5,"Aizzz",41));
Collections.sort(al);
Iterator it = al.iterator();
while(it.hasNext())
{ …Run Code Online (Sandbox Code Playgroud) 如何计算分数中第一个有效数字的位置?
以下是一些具有所需输出的示例输入
0.123456 // 1st sign. number position = 1
0.0012345 // ... = 3
0.000012345 // ... = 5
Run Code Online (Sandbox Code Playgroud) 我正在从数据库中检索字符串并将其存储到for循环内的String变量中.我正在检索的几个字符串的形式为:
https://www.ppltalent.com/test/en/soln-computers-ltd
很少有人的形式
https://www.ppltalent.com/test/ja/aman-computers-ltd
我希望将字符串分成两个子串,即
https://www.ppltalent.com/test/en/soln-computers-ltdas https://www.ppltalent.com/test/en和/soln-computers-ltd.
如果我只有它,它可以很容易地分开/en.
String[] parts = stringPart.split("/en");
System.out.println("Divided String : "+ parts[1]);
Run Code Online (Sandbox Code Playgroud)
但在它的许多字符串中/jr,/ch等等.
那么如何将它们分成两个子字符串呢?
我是Java初学者,但我认为在使用try-catch-finally时我不必使用声明异常throws SQLException.但是,如果我不使用它,编译器会给我错误:
"未报告的异常java.sql.SQLException;必须被捕获或声明被抛出".
我包含了一个catch,所以我不确定为什么会出现这种错误.
public static ResultSet getResultSet ( String query )
{
dbConn = getConnection();
try
{
stmt = dbConn.createStatement( );
ResultSet rs = stmt.executeQuery( query );
return rs;
}
catch (SQLException ex)
{
return null;
}
finally
{
stmt.close();
dbConn.close();
}
}
Run Code Online (Sandbox Code Playgroud) 我知道这对于正常的整数,但是对于像指数这样的东西吗?
Random dice = new Random();
int n = dice.nextInt(6);
System.out.println(n);
Run Code Online (Sandbox Code Playgroud) 任何人都可以帮助我从函数返回数组X().我想将该数组Y()作为参数传递给同一个类中的参数.
是)我有的:
int[] create()throws IOException {
System.out.println("Enter Size of Array");
BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
n=Integer.parseInt(b.readLine());
//A=new int[n];
System.out.println("Enter Array"); for(i=0;i<n;i++) {
int y=Integer.parseInt(b.readLine());
A[i]=y;
}
return A;
}
void getarray() {
}
Run Code Online (Sandbox Code Playgroud) 在使用ArrayList时,我有点新鲜.我知道如何使用字符串创建一个ArrayList,我知道如何用Integers创建一个.我想知道,我如何创建一个包含两种类型的ArrayList,例如Doubles和Chars(但没有别的).
这就是我的意思,
ArrayList<double && char> DCList = new ArrayList<double && char>();
Run Code Online (Sandbox Code Playgroud)
显然它不是有效的Java代码,所以我的问题是,我该如何正确表达它?
在这个简单的程序中我不能返回2个整数值,你能帮帮我吗?我能怎么做 ?
public class Aritmetica
{
public static int div(int x , int y)
{
int q = 0 ;
int r = x ;
while ( r >= y )
{
r = r - y ;
q = q + 1 ;
}
return r && q; **// Here i want to return x and y**
}
public static void main(String[ ] args)
{
if ( ( x <=0 ) & ( y > 0 ) )
throw …Run Code Online (Sandbox Code Playgroud) java ×10
collections ×2
arrays ×1
asynchronous ×1
comparable ×1
compilation ×1
decimal ×1
exception ×1
function ×1
integer ×1
parameters ×1
printf ×1
return ×1