java初学者必会试题
2021/8/2 20:40:35
本文主要是介绍java初学者必会试题,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
package 练习;
import java.util.Arrays;
import java.util.Scanner;
import org.junit.Test;
public class two {
public static void main(String[] args) {
}
@Test
public void Text1(){
System.out.println("Hello");
}
@Test
public void Test2(){
System.out.println("world");
}
@Test
public void Testswitch2(){
System.out.println("请输入月份:");
int m=new Scanner(System.in).nextInt();
switch (m){
case 1:
System.out.println("31");
break;
case 2:
System.out.println("28");
break;
case 3:
System.out.println("31");
break;
case 4:
System.out.println("30");
break;
case 5:
System.out.println("31");
break;
case 6:
System.out.println("30");
break;
case 7:
System.out.println("31");
break;
case 8:
System.out.println("31");
break;
case 9:
System.out.println("30");
break;
case 10:
System.out.println("31");
break;
case 11:
System.out.println("30");
break;
case 12:
System.out.println("31");
break;
default:
System.out.println("输入错误,请输入1到12月份");
}
}
@Test
public void Testswitch3(){
System.out.println("请输入一个月份;");
int m=new Scanner(System.in).nextInt();
switch(m){
case 1 :case 2: case 3:
System.out.println("春天");
break;
case 4 :case 5: case 6:
System.out.println("夏天");
break;
case 7:case 8: case 9:
System.out.println("秋天");
break;
case 10 :case 11: case 12:
System.out.println("冬天");
break;
default:
System.out.println("封思源是我儿");
}
}
@Test
public void Testswitch4(){
System.out.println("请输入一个数字");
int n=new Scanner(System.in).nextInt();
switch(n){
case 0:
System.out.println("星期一");
break;
case 1:
System.out.println("星期二");
break;
case 2:
System.out.println("星期三");
break;
case 3:
System.out.println("星期四");
break;
case 4:
System.out.println("星期五");
break;
case 5:
System.out.println("星期六");
break;
case 6:
System.out.println("星期日");
break;
default:
System.out.println("克依木是我儿");
}
}
@Test
public void Testswitch5(){
System.out.println("请输入员工等级:");
String grade=new Scanner(System.in).next();
switch(grade){
case "A":
System.out.println("加薪数量500");
break;
case "B":
System.out.println("加薪数量300");
break;
case "C":
System.out.println("加薪数量100");
break;
default:
System.out.println("其他级别输入错误");
}
}
@Test
public void Continue(){
for(int i=100;i<=200;i++){
if(i%3!=0){
System.out.println(i);
continue;
}
}
}
@Test
public void Continue2(){
int j= 0;
for(int i=1;i<=10000;i++){
j=j+i;
}
System.out.println(j);
}
@Test
public void estswiTtch8(){
for(int j=1;j<=9;j++){
for(int i=j;i<=9;i++){
System.out.print(j+"*"+i+"="+i*j+"\t");
}
System.out.println();
}
}
@Test
public void Testswitch9(){
int arr[]={16,45,165,541,46};
int k=arr[0];
for(int i=0;i<arr.length;i++){
if(arr[i]<k){
k=arr[i];
}
}System.out.println(k);
}
@Test
public void Testswitch10(){
int arr[]={5555,45456464,4948135,45421548,8487878};
int k=arr[0];
for(int i=0;i<arr.length;i++){
if(k<arr[i]){
k=arr[i];
}
}
System.out.println(k);
}
@Test
public void Testswitch11(){
int arr[]={45145,121241,1121215,545};
Arrays.sort(arr);
for(int i=0;i<4;i++){
System.out.println(arr[i]);
}
}
@Test
public void Testswitch13(){
int WHY[]={12,45,56,98,250};
Arrays.sort(WHY);
for(int i = 0;i<5;i++)
{
System.out.println(WHY[i]);
}
}
这篇关于java初学者必会试题的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-27消息中间件底层原理资料详解
- 2024-11-27RocketMQ底层原理资料详解:新手入门教程
- 2024-11-27MQ底层原理资料详解:新手入门教程
- 2024-11-27MQ项目开发资料入门教程
- 2024-11-27RocketMQ源码资料详解:新手入门教程
- 2024-11-27本地多文件上传简易教程
- 2024-11-26消息中间件源码剖析教程
- 2024-11-26JAVA语音识别项目资料的收集与应用
- 2024-11-26Java语音识别项目资料:入门级教程与实战指南
- 2024-11-26SpringAI:Java 开发的智能新利器