1.输入两个数进行互换
import java.util.Scanner; public class h331 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); System.out.println("请输入俩个数"); int a=input.nextInt(); int b=input.nextInt(); int c; c=a; a=b; b=c; System.out.println("俩个数交换后"); System.out.println(+a); System.out.println(+b); } }
2.输入两个数进行平方求和
import java.util.Scanner; public class h331 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); System.out.println("请输入俩个数"); int a=input.nextInt(); int b=input.nextInt(); int sum; sum=a*a+b*b; System.out.println("俩个数平方和后"+sum); } }
3.输入商品的单价,数量求总价。活动打八折抹零计算价格。输入付款金额,计算找零并输出
import java.util.Scanner; public class h331 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); System.out.println("请输入商品单价"); double a=input.nextDouble(); System.out.println("请输入商品数量"); int b=input.nextInt(); double sum1,sum2; sum1=a*b; sum2=(int)(sum1*0.8); System.out.println("商品总价为"+sum1); System.out.println("商品活动价为"+sum2); System.out.println("请输入付款金额"); double c=input.nextDouble(); double l=(int)(c-sum2); System.out.println("应找零"+l); } }
4.输入三位数,求各位十位百位
import java.util.Scanner; public class h331 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); System.out.println("请输入一个三位数"); int a=input.nextInt(); int g,s,b; g=a%10; s=a%100/10; b=a/100; System.out.println("三位数个位,十位,百位分别为"+g+s+b); } }
5.输入大写字母,输出对应的小写字母
import java.util.Scanner; public class h331 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); System.out.println("请输入一个字母"); char a=input.next().charAt(0); System.out.println("对应的小写字母为"+(char)(a+32)); } }
6.输入俩个数,用三目运算符,输出较大数
import java.util.Scanner; public class h331 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); System.out.println("请输入第一个数"); int a=input.nextInt(); System.out.println("请输入第二个数"); int b=input.nextInt(); int max=a>b?a:b; System.out.println("输出较大数为"+max); } }
原文:https://www.cnblogs.com/hyp33/p/14589056.html