1 .输入一个int值,并在控制台打印
package com.itheima.test;
import java.util.Scanner;
public class Homework1 {
public static void main(String[] args) {
//输入一个int值,并在控制台打印
Scanner sc =new Scanner(System.in);
int r = sc.nextInt( ) ;
System.out.println("这个值为:"+r);
}
}
2 . 输入两个int值,对他们求和将结果打印在控制台
package com.itheima.test;
import java.util.Scanner;
public class Homework2 {
public static void main(String[] args) {
// 输入两个int值,对他们求和将结果打印在控制台
Scanner sc = new Scanner(System.in);
int a =sc.nextInt( );
int b =sc.nextInt( );
System.out.println("第一个值为:"+a);
System.out.println("第二个值为:"+b);
int sum =a + b;
System.out.println(sum);
}
}
3 . 输入两个int值,判断他们是否相等
package com.itheima.test;
import java.util.Scanner;
public class Homework3 {
public static void main(String[] args) {
// 输入两个int值,判断他们是否相等
Scanner sc = new Scanner(System.in);
int a = sc.nextInt( );
int b = sc.nextInt( );
System.out.println("输入值:"+a) ;
System.out.println("输入值:"+b) ;
boolean c = (a == b)? true: false;
System.out.println(c);
}
}