Java学习第一天

本文介绍了Java环境变量配置方法,包括JAVA_HOME、PATH和CLASSPATH的设置,并通过实例演示了如何使用Scanner类读取用户输入,以及如何实现if条件语句和switch-case结构来处理不同的输入值。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

环境变量的配置:

1.创建变量:JAVA_HOME :指向安装jdk的目录

                    PATH: 指向jdk下的bin目录

                    CLASSPATH:默认为.

之后进行程序的编写:我的第一个Java程序


public class day1

    public  static void main(){

         System.out.println("我的第一个Java程序");

}


2.Scanner的使用


package Day01;

import java.util.Scanner;//导入包

public class ScannerDemo {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scan = new Scanner(System.in);//
			System.out.println("输入年龄:");
				int age = scan.nextInt();
		System.out.println("输出年龄:"+age);
	}

}

3 if结构

if(关系表达式)  {执行语句块}




package Day01;
import java.util.Scanner;
public class grod {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		System.out.println("请输入成绩:");
		int a = scan.nextInt();
		if(a>=90) {
			System.out.println("成绩为优秀");
			
		}else { if(a<90 && a>=80){
			System.out.println("成绩为良好");
			}else { if(a<80 && a>=60){
			System.out.println("成绩及格");
				}
			}	
		System.out.println("不及格");
		}
	}

}




package Day01;
/*

*if-else语句的使用
*
*/
import java.util.Scanner;
public class Score {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		System.out.println("请输入成绩:");
		int a = scan.nextInt();
		 if(a<0 || a>100) { 
			 System.out.println("成绩不合法");
		 	}else if(a>=90) {  
				System.out.println("成绩为优秀");
			}else if(a<90 && a>=80){
				System.out.println("成绩为良好");
			}else if(a<80 && a>=60){
				System.out.println("成绩及格");
			}else if(a<60) {
				System.out.println("不及格");
		 	}else {
		 		System.out.println("成绩不合法");}
		
}
	}
	










package Day01;
/*
 * Switch-case使用
 */
import java.util.Scanner;

public class Switchcase {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		System.out.println("数字1-3都有一句话,输入其他数字查看全部内容,\n输入一个数字擦查看:");
		int mun = scan.nextInt();
		switch (mun) {  //byte short int char
		
		case 1:
			System.out.println("l miss you");
			break;//跳出Switch
		case 2:
			System.out.println("l love you");
			break;
		case 3:
			System.out.println("l ready for you");
			break;
		default://所有case都没有匹配上时候执行
			System.out.println("l miss you\nl love you\nl ready for you");
			
		}

	}

}



package Day01;

public class ForXunH {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int count= 0;
		for(;count<=10;count++) {
			System.out.print(count+"----l ready for you\n");
		}	
	    }
	}

package Day01;

public class ForXunH {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int count= 0;
		for(;count<=10;count++) {
			if(count==9) continue;
			System.out.print(count+"----l ready for you\n");
		}	
	   }
	}


package Day01;

public class ForXunH {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int count= 0;
		for(;count<=10;count++) {
			//if(count==9) continue;
			if(count==9) break;
			System.out.print(count+"----l ready for you\n");
		}
            }
	}
















评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值