JAVA编程 要有Scanner,if else 语句
输入两个整数,放入到变量a和b中,如果a大于等于b,把a和b的值进行交换,否则就不交换,最后输出a和b的值用ifelse语句,要有Scanner...
输入两个整数,放入到变量a和b中, 如果a大于等于b,把a和b的值进行交换, 否则就不交换,最后输出a和b的值
用 if else 语句,要有Scanner 展开
用 if else 语句,要有Scanner 展开
3个回答
展开全部
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int a = scan.nextInt();
int b = scan.nextInt();
if (a >= b) {
int temp = a;
a = b;
b = temp;
System.out.println("a = " + a);
System.out.println("b = " + b);
} else {
System.out.println("a = " + a);
System.out.println("b = " + b);
}
scan.close();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
int a = 0;
int b = 0;
int temp = 0;
Scanner scanner = new Scanner(System.in);
System.out.println("输入两个整数数a,b");
a = scanner.nextInt();
b = scanner.nextInt();
if (b < a) {
temp = a;
a = b;
b = temp;
}
System.out.println(a + " " + b);
随意写了一下,您看是否对您有所帮助
int b = 0;
int temp = 0;
Scanner scanner = new Scanner(System.in);
System.out.println("输入两个整数数a,b");
a = scanner.nextInt();
b = scanner.nextInt();
if (b < a) {
temp = a;
a = b;
b = temp;
}
System.out.println(a + " " + b);
随意写了一下,您看是否对您有所帮助
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
package ScannerTest;
import java.util.Scanner;
public class ScannerTest {
public static void main(String[] Args){
Scanner scanner = new Scanner(System.in);
int temp = 0;
System.out.println("a=");
int a = scanner.nextInt();
System.out.println("b=");
int b = scanner.nextInt();
if(a>b){
temp = a;
a = b;
b = temp ;
}else{
}
System.out.println("a = "+ a +"\n1b = "+ b);
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询