输出事实:This is a simple problem.
1 public class Main { 2 public static void main(String args[]){ 3 System.out.println("This is a simple problem."); 4 } 5 }
请编写程序,在屏幕上显示孔子的名言。
注:无输入。
学而不思则罔,
思而不学则殆。
提示:标点符号为中文全角符号。
public class Main { public static void main(String[] args){ System.out.println("学而不思则罔,"); System.out.println("思而不学则殆。"); } }
据说所有程序员学习的第一个程序都是在屏幕上输出一句“Hello World”,跟这个世界打个招呼。作为天梯赛中的程序员,你写的程序得高级一点,要能跟任意指定的星球打招呼。
输入在第一行给出一个星球的名字S
,是一个由不超过7个英文字母组成的单词,以回车结束。
在一行中输出Hello S
,跟输入的S
星球打个招呼。
Mars
Hello Mars
1 import java.util.Scanner; 2 public class Main { 3 public static void main(String args[]){ 4 Scanner sc=new Scanner(System.in); 5 String s=sc.next(); 6 System.out.println("Hello "+s); 7 } 8 }
你只需要把这句很重要的话 —— I Love GPLT
——竖着输出就可以了。
所谓“竖着输出”,是指每个字符占一行(包括空格),即每行只能有1个字符和回车。
1 public class Main { 2 public static void main(String[] args){ 3 System.out.println("I\n \nL\no\nv\ne\n \nG\nP\nL\nT"); 4 5 } 6 }
给定两个绝对值不超过100的整数A和B,输出A乘以B的值。
输入在第一行给出两个整数A和B(?),数字间以空格分隔。
在一行中输出A乘以B的值。
-8 13
-104
1 import java.util.Scanner; 2 3 public class Main{ 4 public static void main(String[] args) 5 { 6 Scanner sc = new Scanner(System.in); 7 int a = sc.nextInt(); 8 int b = sc.nextInt(); 9 System.out.println(a*b); 10 } 11 }
程序每次读入一个正3位数,然后输出按位逆序的数字。注意:当输入的数字含有结尾的0时,输出不应带有前导的0。比如输入700,输出应该是7。
每个测试是一个3位的正整数。
输出按位逆序的数。
123
321
1 import java.util.Scanner; 2 public class Main { 3 public static void main (String [] args ) 4 { 5 Scanner sc = new Scanner(System.in); 6 int a=sc.nextInt(); 7 int b=a%10; 8 int c=a/10; 9 int d=c%10; 10 int e=c/10; 11 int f=b*100+d*10+e; 12 System.out.println(f); 13 14 15 } 16 }
给定一个华氏温度F,本题要求编写程序,计算对应的摄氏温度C。计算公式:2。题目保证输入与输出均在整型范围内。
输入在一行中给出一个华氏温度。
在一行中按照格式“Celsius = C”输出对应的摄氏温度C的整数值。
150
Celsius = 65
1 import java.util.Scanner; 2 public class Main { 3 public static void main (String [] args ) 4 { 5 Scanner sc = new Scanner(System.in); 6 int a=sc.nextInt(); 7 int b=a-32; 8 int s=b*5; 9 int c=s/9; 10 System.out.println("Celsius = "+c); 11 12 13 } 14 }
如果已知英制长度的英尺foot和英寸inch的值,那么对应的米是(。现在,如果用户输入的是厘米数,那么对应英制长度的英尺和英寸是多少呢?别忘了1英尺等于12英寸。
输入在一行中给出1个正整数,单位是厘米。
在一行中输出这个厘米数对应英制长度的英尺和英寸的整数值,中间用空格分开。
170
5 6
1 import java.util.Scanner; 2 public class Main{ 3 public static void main(String[] args){ 4 Scanner sc=new Scanner(System.in); 5 double foot,inch,meter; 6 meter=sc.nextDouble(); 7 foot=(int)(1.44*meter/44.196); 8 inch=(int)(12*(0.01/0.3048*meter-foot)); 9 int b=(int)foot,c=(int)inch; 10 System.out.println(b+" "+c); 11 } 12 }
对任意给定的不超过10的正整数n,要求你输出2^?n??。不难吧?
输入在一行中给出一个不超过10的正整数n。
在一行中按照格式 2^n = 计算结果
输出2?n??的值。
5
2^5 = 32
1 import java.util.Scanner; 2 public class Main { 3 public static void main (String [] args ) 4 { 5 Scanner sc = new Scanner(System.in); 6 int a=sc.nextInt(); 7 int i=a; 8 int s=1; 9 while(i>0) 10 {s=s*2; 11 i=i-1;} 12 System.out.println("2^"+a+" = "+s); 13 14 15 } 16 }
去商场淘打折商品时,计算打折以后的价钱是件颇费脑子的事情。例如原价 ¥988,标明打 7 折,则折扣价应该是 ¥988 x 70% = ¥691.60。本题就请你写个程序替客户计算折扣价。
输入在一行中给出商品的原价(不超过1万元的正整数)和折扣(为[1, 9]区间内的整数),其间以空格分隔。
在一行中输出商品的折扣价,保留小数点后 2 位。
988 7
691.60
1 import java.util.Scanner; 2 public class Main { 3 public static void main (String [] args ) 4 { 5 Scanner sc = new Scanner(System.in); 6 int a=sc.nextInt(); 7 int k=sc.nextInt(); 8 double s=a*k/10.0; 9 System.out.println(s+"0"); 10 11 12 } 13 }
原文:https://www.cnblogs.com/ygy0609/p/14951300.html