输入3科成绩,然后把三科成绩输出,成绩为整数形式。
数据范围:
#include <stdio.h> int main() { //输入三科成绩--0~100 int a[3]; int k = 1; while (k) { //while用于重新输入 for (int i = 0; i < 3; i++) { //用于输入三科成绩 scanf("%d", &a[i]); if (a[i] >= 0 && a[i] <= 100) { //判断输入的成绩是否满足要求:0-100 if (i == 2) { //最后一次输入满足要求 令k=0,跳出while循环 k = 0; } } else //否则,重新输入三科成绩 printf("请输入正确的成绩!\n"); } } //输出三科成绩 for (int i = 0; i < 3; i++) { printf("score%d=%d", i + 1, a[i]); if (i < 2) //最后一科后面的成绩不加 "," printf(","); } return 0; }
#include<stdio.h> int main() { int a[3],i; for(i=0;i<3;i++) scanf("%d",&a[i]); printf("score1=%d,score2=%d,score3=%d",a[0],a[1],a[2]); }初学者可以用数组试试
//本体考察了Scanner键盘输入的知识点,以及字符串的简单拼接import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner s = new Scanner(System.in); int a = s.nextInt(); int b = s.nextInt(); int c = s.nextInt(); setScore(a,b,c); } public static void setScore(int score1, int score2, int score3){ System.out.print("score1=" + score1); System.out.print(",score2=" + score2); System.out.print(",score3=" + score3); } }
import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner input=new Scanner(System.in); int j=3;//科数可以改变,也可不加,直接循环定义 for (int i = 1; i <=j ; i++) { int a=input.nextInt(); if (i==j){ System.out.print("score" + i + "=" + a); }else { System.out.print("score" + i + "=" + a+","); } } } }
#include<stdio.h> int main() { int a,b,c; scanf("%d %d %d",&a,&b,&c); printf("score1=%d,score2=%d,score3=%d",a,b,c); return 0; }
import java.util.*; public class Main { public static void main(String [] args) { Scanner sc=new Scanner(System.in); while(sc.hasNextLine()) { String score=sc.nextLine(); String [] arr=score.split(" "); for(int i=0;i<arr.length;i++) { if(i==arr.length-1) { System.out.print("score"+(i+1)+"="+arr[i]); } else { System.out.print("score"+(i+1)+"="+arr[i]+","); } } System.out.println(); } } }
import java.util.Scanner;
public class Main {
public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String input = scanner.nextLine(); /** * nextInt(): * * 只读取整数类型数据, nextInt()在读取完输入后把光标放在读取数据的同一行,该数据的后面。 * * next(): * * 只读取到空格,不能读取被空格分开的两个单词(也就是不能读取空格),并且在读取完后把光标放在读取数据的同一行,该数据的后面。(同上) * * nextLine(): * 读取整行的数据包括单词间的空格,到回车结束(也就是从开始读一整行包括回车),读取结束后,光标放在下一行开头。 */ String[] str = input.split(" "); System.out.println("score1="+str[0]+",score2="+str[1]+",score3="+str[2]); }
}
#include <stdio.h> #define n 100 int main() { int arr[n]={0}; int i=0; while(scanf("%d",&arr[i])!=EOF&&i<n) { i++; } int j=0; for(j=0;j<i;j++) { if(j<i-1) { printf("score%d=%d,",j+1,arr[j]); } else { printf("score%d=%d",j+1,arr[j]); } } return 0; }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int s1 = scanner.nextInt(); int s2 = scanner.nextInt(); int s3 = scanner.nextInt(); System.out.println("score1=" + s1 + "," + "score2=" + s2 + "," + "score3=" + s3); } }