java中Scanner的方法调用
importjava.util.Scanner;publicclassCompareTwoNumbers1{doublenumber1,number2;Scannersc...
import java.util.Scanner;
public class CompareTwoNumbers1
{
double number1,number2;
Scanner scanner;
public CompareTwoNumbers1()
{
System.out.println("请输入两个数字:");
scanner=new Scanner(代码1);//实例化一个Scanner对象;
number1=代码2; //从键盘输入一个整数赋值给number1;
number2=代码3;//从键盘输入一个整数赋值给number2;
System.out.println("较大的数值是:"代码4);//将number1和number2中较大值输出;
}
public static void main(String args[])
{
CompareTwoNumbers1 ct=new CompareTwoNumbers1();
System.exit(0);
}
}
四个代码应该怎么处理,代码4中,Scanner调用什么方法可以取得最大值? 展开
public class CompareTwoNumbers1
{
double number1,number2;
Scanner scanner;
public CompareTwoNumbers1()
{
System.out.println("请输入两个数字:");
scanner=new Scanner(代码1);//实例化一个Scanner对象;
number1=代码2; //从键盘输入一个整数赋值给number1;
number2=代码3;//从键盘输入一个整数赋值给number2;
System.out.println("较大的数值是:"代码4);//将number1和number2中较大值输出;
}
public static void main(String args[])
{
CompareTwoNumbers1 ct=new CompareTwoNumbers1();
System.exit(0);
}
}
四个代码应该怎么处理,代码4中,Scanner调用什么方法可以取得最大值? 展开
5个回答
展开全部
//我给补全了,两个数值比较用Math类的max(double,double)方法
import java.util.Scanner;
public class CompareTwoNumbers1 {
double number1, number2;
Scanner scanner;
public CompareTwoNumbers1() {
System.out.println("请输入两个数字:");
scanner = new Scanner(System.in);// 实例化一个Scanner对象;
number1 = scanner.nextDouble(); // 从键盘输入一个整数赋值给number1;
number2 = scanner.nextDouble();// 从键盘输入一个整数赋值给number2;
System.out.println("较大的数值是:" + Math.max(number1, number2));// 将number1和number2中较大值输出;
}
public static void main(String args[]) {
CompareTwoNumbers1 ct = new CompareTwoNumbers1();
System.exit(0);
}
}
import java.util.Scanner;
public class CompareTwoNumbers1 {
double number1, number2;
Scanner scanner;
public CompareTwoNumbers1() {
System.out.println("请输入两个数字:");
scanner = new Scanner(System.in);// 实例化一个Scanner对象;
number1 = scanner.nextDouble(); // 从键盘输入一个整数赋值给number1;
number2 = scanner.nextDouble();// 从键盘输入一个整数赋值给number2;
System.out.println("较大的数值是:" + Math.max(number1, number2));// 将number1和number2中较大值输出;
}
public static void main(String args[]) {
CompareTwoNumbers1 ct = new CompareTwoNumbers1();
System.exit(0);
}
}
展开全部
scanner= new Scanner(System.in);
number1=scanner.nextDouble();
number2=scanner.nextDouble();
System.out.println("较大的数值是:"+Math.max(number1,number2) );
number1=scanner.nextDouble();
number2=scanner.nextDouble();
System.out.println("较大的数值是:"+Math.max(number1,number2) );
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Scanner没有这种方法吧~
System.out.println("较大的数值是:"+(Double.parseDouble(number1+"")>Double.parseDouble(number2+"")?Double.parseDouble(number1+""):Double.parseDouble(number2+"")));//将number1和number2中较大值输出;
Math.max(double double)也不错啊;~
System.out.println("较大的数值是:"+(Double.parseDouble(number1+"")>Double.parseDouble(number2+"")?Double.parseDouble(number1+""):Double.parseDouble(number2+"")));//将number1和number2中较大值输出;
Math.max(double double)也不错啊;~
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Scanner scanner = new Scanner(System.in);
String string = scanner.nextLine();
String string = scanner.nextLine();
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
1.System.in
2.scanner.nextInt()
3.scanner.nextInt()
4.+Math.max(number1,number2)
2.scanner.nextInt()
3.scanner.nextInt()
4.+Math.max(number1,number2)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询