JAva 2回目の搭乗
9829 ワード
1.プログラムを作成し、変数xの値を入力し、1であれば、出力x=1、5であれば、出力x=5、10であれば、出力x=10、以上のいくつかの値を除いて、x=noneを出力します.(知識点:if条件文)
2.switch構造で第1題を実現
3.1つの数字が5と6で同時に割り切れるか(印刷は5と6で割り切れる)、5で割り切れるか(印刷は5で割り切れる)、6で割り切れるか(印刷は6で割り切れる)、5または6で割り切れるか(印刷は5または6で割り切れる)を判断します.
4..0~100のスコアを入力し、0~100の間でなければ無効な印刷スコアで、スコアレベルに応じてA(90-100)、B(80-89)、C、D、E(知識点:条件文if elseif)を印刷します.
5.3つの整数x,y,zを入力し、この3つの数を小さいから大きいまで出力してください(知識点:条件文)
package Text;
import java.util.Scanner;
public class zuoye2 {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
System.out.println(" x ");
int x=sc.nextInt();
if(x==1 || x==5 || x==10) {
System.out.println("x="+x);
}else {
System.out.println("x=none");
}
}
}
2.switch構造で第1題を実現
package Text;
import java.util.Scanner;
public class zuoye2 {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
System.out.println(" x ");
int x=sc.nextInt();
switch(x) {
case 1:
case 5:
case 10:System.out.println("x="+x);break;
default:System.out.println("x=none");
}
}
}
3.1つの数字が5と6で同時に割り切れるか(印刷は5と6で割り切れる)、5で割り切れるか(印刷は5で割り切れる)、6で割り切れるか(印刷は6で割り切れる)、5または6で割り切れるか(印刷は5または6で割り切れる)を判断します.
package Text;
import java.util.Scanner;
public class zuoye2 {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
System.out.println(" ");
int x=sc.nextInt();
if(x%5==0 && x%6==0) {
System.out.println(x+" 5 6 ");
}else if(x%5==0 ){
System.out.println(x+" 5 ");
}else if(x%6==0) {
System.out.println(x+" 6 ");
}else {
System.out.println(x+" 5 6 ");
}
}
}
4..0~100のスコアを入力し、0~100の間でなければ無効な印刷スコアで、スコアレベルに応じてA(90-100)、B(80-89)、C、D、E(知識点:条件文if elseif)を印刷します.
package Text;
import java.util.Scanner;
public class zuoye2 {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
System.out.println(" ");
int x=sc.nextInt();
if(x<0 || x>100) {
System.out.println(" ");
}else if(x/10>=9 && x/10<=10) {
System.out.println("A");
}else if(x/10>=8 & x/10<9) {
System.out.println("B");
}else if(x/10>=7 & x/10<8) {
System.out.println("C");
}else if(x/10>=6 & x/10<7) {
System.out.println("D");
}else if(x/10<6) {
System.out.println("E");
}
}
}
5.3つの整数x,y,zを入力し、この3つの数を小さいから大きいまで出力してください(知識点:条件文)
package Text;
import java.util.Scanner;
public class zuoye2 {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
System.out.println(" x ");
int x=sc.nextInt();
System.out.println(" y ");
int y=sc.nextInt();
System.out.println(" z ");
int z=sc.nextInt();
if(x>y && y>z) {
System.out.println(" "+z+","+y+","+x);
}else if(x>z && z>y) {
System.out.println(" "+y+","+z+","+x);
}else if(y>x && x>z) {
System.out.println(" "+z+","+x+","+y);
}else if(y>z && z>x) {
System.out.println(" "+x+","+z+","+y);
}else if(z>y && y>x) {
System.out.println(" "+x+","+y+","+z);
}else if(z>x && x>y) {
System.out.println(" "+y+","+x+","+z);
}
}
}