7-1 模仿练习
public class Main {
public static void main(String[] args) throws Exception {
System.out.println("Programming is fun!");
System.out.println("Fundamentals First");
System.out.println("Problem Driven");
}
}
7-2 Hello World!
public class Main {
public static void main(String[] args) throws Exception {
System.out.println("Hello World!");
}
}
7-3 sdut-入门-交换两个整数的值
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws Exception {
Scanner reader = new Scanner(System.in);
int a, b, temp;
a = reader.nextInt();
b = reader.nextInt();
temp = a;
a = b;
b = temp;
System.out.print(a + " " + b);
reader.close();
}
}
7-4 sdut-入门-转换字母
import java.util.*;
public class Main {
public static void main(String[] args){
String a;
Scanner input = new Scanner(System.in);
a = input.nextLine();
System.out.println(a.toUpperCase());
input.close();
}
}
7-5 球的表面积和体积
import java.util.Scanner;
import java.text.DecimalFormat;
public class Main
{
public static void main(String[] args)
{
Scanner reader = new Scanner(System.in);
double d1 = reader.nextDouble();
double s, v, p;
p = 3.1415926535;
s = 4 * d1 * d1 * p;
v = (4 * p * d1 * d1 * d1) / 3;
DecimalFormat df = new DecimalFormat("0.00");
System.out.print(df.format(s) + " " + df.format(v));
}
}
7-6 华氏温度转化为摄氏温度
import java.text.DecimalFormat;
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
double c;
double f = in.nextDouble();
c = (f - 32) * 5 / 9;
DecimalFormat df = new DecimalFormat("0.00");
System.out.println("c="+df.format(c));
in.close();
}
}
7-7 sdut-入门-1 A+B for Input-Output Practice(I)
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner reader = new Scanner(System.in);
int a, b, c;
while(reader.hasNext())
{
a = reader.nextInt();
b = reader.nextInt();
c = a + b;
System.out.println(c);
}
reader.close();
}
}
7-8 sdut-入门-2 A+B for Input-Output Practice (II)
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner reader = new Scanner(System.in);
int a, b, m, c;
m = reader.nextInt();
while(m-- >0)
{
a = reader.nextInt();
b = reader.nextInt();
c = a + b;
System.out.println(c);
}
reader.close();
}
}
7-9 sdut0-入门-3 A+B for Input-Output Practice (III)
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
while(in.hasNext())
{
int a, b;
a = in.nextInt();
b = in.nextInt();
if(a == 0 && b == 0) break;
System.out.println(a + b);
}
}
}
7-10 sdut-入门-4 A+B for Input-Output Practice (IV)
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
while(in.hasNext())
{
int n = in.nextInt();
if(n == 0) break;
int sum = 0;
for(int i = 0; i < n; i ++)
{
int x = in.nextInt();
sum += x;
}
System.out.println(sum);
}
}
}
7-11 sdut-入门-5 A+B for Input-Output Practice (V)
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner reader = new Scanner(System.in);
int x, n, m;
m = reader.nextInt();
while(m-- >0)
{
x = 0;
n = reader.nextInt();
while(n-- > 0)
{
x += reader.nextInt();
}
System.out.println(x);
}
reader.close();
}
}
7-12 sdut-入门-6 A+B for Input-Output Practice (VI)
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
while(in.hasNext())
{
int n = in.nextInt();
int sum = 0;
for(int i = 0; i < n; i ++)
{
int x = in.nextInt();
sum += x;
}
System.out.println(sum);
}
}
}
7-13 sdut-入门-7 A+B for Input-Output Practice (VII)
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
while(in.hasNext())
{
int a = in.nextInt();
int b = in.nextInt();
System.out.println(a + b);
System.out.println();
}
}
}
7-14 sdut-入门-8 A+B for Input-Output Practice(VIII)
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner reader = new Scanner(System.in);
int x, n, m;
m = reader.nextInt();
while(m-- >0)
{
x = 0;
n = reader.nextInt();
while(n-- > 0)
{
x += reader.nextInt();
}
System.out.println(x);
System.out.println();
}
reader.close();
}
}
7-15 打印字母B。
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
System.out.println("*****");
System.out.println("* *");
System.out.println("*****");
System.out.println("* *");
System.out.println("*****");
}
}