赞
踩
编写一个能够输出
Hello,World!
的程序。提示:
- 使用英文标点符号;
Hello,World!
逗号后面没有空格。H
和W
为大写字母。
Hello,World!
无
Hello,World!
import java.util.*;
public class Main{
public static void main(String[] args){
System.out.print("Hello,World!");
}
}
用
*
构造一个对角线长 5 5 5 个字符,倾斜放置的菱形。
没有输入要求。
如样例所示。用
*
构成的菱形。
*
***
*****
***
*
import java.util.*;
public class Main{
public static void main(String[] args){
System.out.println(" *");
System.out.println(" ***");
System.out.println("*****");
System.out.println(" ***");
System.out.println(" *");
}
}
超级玛丽是一个非常经典的游戏。请你用字符画的形式输出超级玛丽中的一个场景。
******** ************ ####....#. #..###.....##.... ###.......###### ### ### ........... #...# #...# ##*####### #.#.# #.#.# ####*******###### #.#.# #.#.# ...#***.****.*###.... #...# #...# ....**********##..... ### ### ....**** *****.... #### #### ###### ###### ############################################################## #...#......#.##...#......#.##...#......#.##------------------# ###########################################------------------# #..#....#....##..#....#....##..#....#....##################### ########################################## #----------# #.....#......##.....#......##.....#......# #----------# ########################################## #----------# #.#..#....#..##.#..#....#..##.#..#....#..# #----------# ########################################## ############
无
如描述
import java.util.*; public class Main{ public static void main(String[] args) { System.out.println(" ******** "); System.out.println(" ************ "); System.out.println(" ####....#. "); System.out.println(" #..###.....##.... "); System.out.println(" ###.......###### ### ### "); System.out.println(" ........... #...# #...#"); System.out.println(" ##*####### #.#.# #.#.#"); System.out.println(" ####*******###### #.#.# #.#.#"); System.out.println(" ...#***.****.*###.... #...# #...#"); System.out.println(" ....**********##..... ### ###"); System.out.println(" ....**** *****.... "); System.out.println(" #### #### "); System.out.println(" ###### ###### "); System.out.println("##########################################"); System.out.println("#...#......#.##...#......#.##...#......#.##------------------#"); System.out.println("###########################################------------------#"); System.out.println("#..#....#....##..#....#....##..#....#....#####################"); System.out.println("########################################## #----------#"); System.out.println("#.....#......##.....#......##.....#......# #----------#"); System.out.println("########################################## #----------#"); System.out.println("#.#..#....#..##.#..#....#..##.#..#....#..# #----------#"); System.out.println("########################################## ############"); } }
输入两个整数 a , b a, b a,b,输出它们的和( ∣ a ∣ , ∣ b ∣ ≤ 10 9 |a|,|b| \le {10}^9 ∣a∣,∣b∣≤109)。
两个以空格分开的整数。
一个整数。
20 30
50
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner cin=new Scanner(System.in);
int a = cin.nextInt(), b = cin.nextInt();
System.out.println(a+b);
}
}
给定一个字符,用它构造一个底边长 5 5 5 个字符,高 3 3 3 个字符的等腰字符三角形。
输入只有一行,包含一个字符。
该字符构成的等腰三角形,底边长 5 5 5 个字符,高 3 3 3 个字符。
*
*
***
*****
对于 100 % 100 \% 100% 的数据,输入的字符是 ASCII 中的可见字符。
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
char inputChar = sc.next().charAt(0);
System.out.println(" " + inputChar);
System.out.println(" " + inputChar + inputChar + inputChar);
System.out.println(""+inputChar + inputChar + inputChar + inputChar + inputChar);
}
}
现在需要采购一些苹果,每名同学都可以分到固定数量的苹果,并且已经知道了同学的数量,请问需要采购多少个苹果?
输入两个不超过 1 0 9 10^9 109 正整数,分别表示每人分到的数量和同学的人数。
一个整数,表示答案。保证输入和答案都在 int 范围内的非负整数。
5 3
15
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int a=sc.nextInt(),b=sc.nextInt();
System.out.print(a*b);
}
}
输入一个小写字母,输出其对应的大写字母。例如输入 q[回车] 时,会输出 Q。
无
无
q
Q
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
char input=sc.next().charAt(0);
char output=Character.toUpperCase(input);
System.out.println(output);
}
}
输入一个不小于 100 100 100 且小于 1000 1000 1000,同时包括小数点后一位的一个浮点数,例如 123.4 123.4 123.4 ,要求把这个数字翻转过来,变成 4.321 4.321 4.321 并输出。
一行一个浮点数
一行一个浮点数
123.4
4.321
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
double input=sc.nextDouble();
if(input>=100&&input<1000){
String str=String.format("%.1f",input);
String reverseNum=new StringBuffer(str).reverse().toString();
double reversed=Double.parseDouble(reverseNum);
System.out.print(reversed);
}
}
}
①先把数字串转化为字符串:
String str=String.format(“%.1f”,input);
②把字符串翻转过来
String reverseNum=new StringBuffer(str).reverse().toString();
③把翻转过来的字符串转化为数字串
double reversed=Double.parseDouble(reverseNum);
现在有 t t t 毫升肥宅快乐水,要均分给 n n n 名同学。每名同学需要 2 2 2
个杯子。现在想知道每名同学可以获得多少毫升饮料(严格精确到小数点后 3 3 3 位),以及一共需要多少个杯子。
输入一个实数 t t t 和一个正整数 n n n,使用空格隔开。
输出两行。
第一行输出一个三位小数,表示可以获得多少毫升饮料。第二行输出一个正整数,表示一共需要多少个杯子。
500.0 3
166.667
6
对于所有数据, 0 ≤ t ≤ 10000 0\leq t\leq 10000 0≤t≤10000 且小数点后不超过 3 3 3 位, 1 ≤ n ≤ 1000 1\leq n\leq 1000 1≤n≤1000。
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
double t=sc.nextDouble();
int n=sc.nextInt();
double water=t/n;
int cup=n*2;
System.out.printf("%.3f%n",water);
System.out.println(cup);
}
}
为什么不能这样输出:System.out.println(“%.3f”,water);?
不能这样输出的原因是,System.out.println()
方法不支持使用格式化字符串。如果你想在输出中保留小数点后三位,可以使用String.format()
方法或者DecimalFormat
类来实现。
例如,使用String.format()
方法:
System.out.println(String.format("%.3f", water));
或者使用DecimalFormat
类:
import java.text.DecimalFormat;
DecimalFormat df = new DecimalFormat("#.###");
System.out.println(df.format(water));
一个三角形的三边长分别是 a a a、 b b b、 c c c,那么它的面积为 p ( p − a ) ( p − b ) ( p − c ) \sqrt{p(p-a)(p-b)(p-c)} p(p−a)(p−b)(p−c) ,其中
p = 1 2 ( a + b + c ) p=\frac{1}{2}(a+b+c) p=21(a+b+c)。输入这三个数字,计算三角形的面积,四舍五入精确到 1 1 1 位小数。
第一行输入三个实数 a , b , c a,b,c a,b,c,以空格隔开。
输出一个实数,表示三角形面积。精确到小数点后 1 1 1 位。
3 4 5
6.0
数据保证能构成三角形, 0 ≤ a , b , c ≤ 1000 0\leq a,b,c\leq 1000 0≤a,b,c≤1000,每个边长输入时不超过 2 2 2 位小数。
学校和 yyy 的家之间的距离为 s s s 米,而 yyy 以 v v v 米每分钟的速度匀速走向学校。
在上学的路上,yyy 还要额外花费 10 10 10 分钟的时间进行垃圾分类。
学校要求必须在上午 8:00 \textrm{8:00} 8:00 到达,请计算在不迟到的前提下,yyy 最晚能什么时候出门。
由于路途遥远,yyy 可能不得不提前一点出发,但是提前的时间不会超过一天。
一行两个正整数 s , v s,v s,v,分别代表路程和速度。
输出一个 24 24 24 小时制下的时间,代表 yyy 最晚的出发时间。
输出格式为 HH:MM \texttt{HH:MM} HH:MM,分别代表该时间的时和分。必须输出两位,不足前面补 0 0 0。
100 99
07:48
对于 100 % 100\% 100% 的数据, 1 ≤ s , v ≤ 1 0 4 1 \le s,v \le 10^4 1≤s,v≤104。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。