自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(21)
  • 收藏
  • 关注

原创 定义方法判断随机数是否存在数组中

import java.util.Random;public class FalseTest { public static void main(String[] args) { int[] array2 = {13, 1314, 520, 14}; //输出打印结果,不然不会打印出来 // System.out.println(a); Random r = new Random(); int c = r

2023-02-22 07:22:36 135

原创 定义方法拷贝数组中部分数值

public class CopyTest { public static void main(String[] args) { int[] array1 = {13, 1314, 520, 14, 12, 16, 11, 1999, 1996}; //定义一个方法,拷贝数组中索引from(包含)到to(不包含)的数值并遍历 int[] array2 = copy(array1,2,6); for (int i = 0; i

2023-02-21 16:47:54 81

原创 数组的问题

public class ArrayTest { public static void main(String[] args) { //数组的第一种格式,int要对应int int[] array1 = new int[]{1, 2, 3, 4, 5}; //简化格式 数组有五个,则索引从0到5,最大索引等于数组长度-1 int array2[] = {6, 7, 8, 9}; //也可以下面这样写,省略等号

2023-02-20 08:45:46 92

原创 键盘录入数组并遍历

//键盘录入数组,并用while语句遍历数组import java.util.Scanner;public class ArrayTest { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int array6[] = new int[3]; System.out.println("请输入第一个数字"); //

2023-02-19 09:08:10 686

原创 数组方法的调用

//定义一个方法,求长方形的周长public class MethodTest { public static void main(String[] args) { //调用方法格式: 方法名(数值); perimeter(13.14, 5.2);//结果为36.68 int[] array1 = {11, 22, 33, 44, 55}; //数组调用方法格式:方法名(数组); method1(arra

2023-02-18 06:14:44 680

原创 方法的重载

//方法的重载:在同一个类中,定义了多个同名的方法,具有同种的功能//同一个类中,方法名相同,参数不同(个数不同,类型不同,顺序不同)//同一个类中,指的是同一个class中//使用方法重载的思想,设计比较两个整数是否相同的方法public class MethodTest { public static void main(String[] args) { compare(10, 10);//注意注意注意:默认整数为int类型 //若要改为by

2023-02-17 12:43:15 55

原创 方法的调动及带返回值的方法调用

//带返回值的方法调用public class MethodTest { public static void main(String[] args) { //调用方法格式: 方法名(数值); //直接调用为36.68 perimeter(13.14, 5.2); //赋值调用为36.68 //注意:本身perimeter(13.14, 5.2)的结果就是自带的sout输出语句 //此时

2023-02-16 07:09:31 65

原创 数组相关知识五(打乱数组中的值并遍历)

//打乱数组中的值并遍历import java.util.Random;public class ArrayTest { public static void main(String[] args) { int [] array8 = {1,2,3,4,5}; Random r = new Random(); for (int i = 0; i < array8.length; i++) { int nu

2023-02-15 12:28:15 37

原创 数组相关知识四(改变数组值并遍历数组)

//改变数组中的值,再重新遍历数组public class Teeest { public static void main(String[] args) { int [] array3 = {1,2,3,4,5,6,7,8,9,10}; for (int i = 0; i < array3.length; i++) { if(array3[i] % 2 == 0){ array3[i] =

2023-02-14 18:32:08 146

原创 数组相关知识三(求数组中的最大值及符合要求的数)

//求数组中的最大值public class Teeest { public static void main(String[] args) { int [] array4 = {52,1314,13,14,520}; //要定义一个数,但是不能是0,因为数组中可能有负数 int max = array4[0]; //若for里面的i初始值为0,则第一个值自我比较,若为1可省略第一步 for (int i = 1; i

2023-02-13 09:16:42 62

原创 数组相关知识二(求数组中的数和及平均数)

//用随机数生成一个数组,求这个数组中的值总和及平均数,//并统计多少个数字比平均值小import java.util.Random;public class Teeest { public static void main(String[] args) { //表示我要用Random这个随机数包了 Random r = new Random(); /

2023-02-12 21:57:51 227

原创 交换变量问题

//定义两个变量,交换两个变量的值,并打印出变化后的值public class Teeest { public static void main(String[] args) { int a = 13; int b = 52; // a = b; // System.out.println(a);//打印出52,因为b的值赋给a了 // System.out.println(b);//打印出52 //

2023-02-11 11:44:55 39

原创 数组相关知识一(交换元素)

/*//定义一个数组,交换首尾索引对应的元素public class Teeest { public static void main(String[] args) { int [] array6 = {1,3,5,7,9,0}; for (int i = 0; i < array6.length; i++) { System.out.print(array6[i]+" "); } //首先要清楚,0

2023-02-10 11:17:51 68 1

原创 三元运算符比较大小

import java.util.Scanner;public class Test { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("请输入第一个人的身高"); double a = sc.nextDouble();//注意注意,前面的double要和next后的对应 Sy

2023-02-09 16:57:42 472

原创 \t制表符的作用

public class TTest { public static void main(String[] args) { int a = 1; int b = a++;//1,加号在后面,先赋值再自增,此时b=1,结束后a=2.减号规则也一样 int c = ++a;//3,在前面,先自增再赋值,此时c=3,结束后a=3(上一步a已经是2了).减号规则也一样 a+=b;//4,把a+b的值赋给左边新a,上一步a=3,b=1,这步结束

2023-02-08 23:07:14 292

原创 switch语句

import java.util.Scanner;public class SwitchTest { public static void main (String[]args){ Scanner sc = new Scanner(System.in); System.out.println("请输入星期"); //nextlnt对应的是int,要想输出字符串String,则需要用nextLine String week

2023-02-07 23:31:41 57

原创 猜数字小游戏

import java.util.Random;//随机数包import java.util.Scanner;//键盘录入包public class Test { public static void main(String[] args) { Random r = new Random();//随机数 Scanner sc = new Scanner(System.in); int number2 = r.nextInt(100);/

2023-02-06 23:52:43 91

原创 赋值运算符

public class TTest { public static void main(String[] args) { int a = 1; int b = a++;//1,加号在后面,先赋值再自增,此时b=1,结束后a=2.减号规则也一样 int c = ++a;//3,在前面,先自增再赋值,此时c=3,结束后a=3(上一步a已经是2了).减号规则也一样 a+=b;//4,把a+b的值赋给左边新a,上一步a=3,b=1,这步结束

2023-02-05 11:42:45 70 1

原创 字母与数字运算结果

public class TTest { public static void main(String[] args) { System.out.println(13.14+"love");//13.14love(多个字母用双引号) System.out.println(5.20+"a");//5.2a(数字直接写就行,无需引号) System.out.println(5.20+'a');//102.2(单引号a在码表中是97)

2023-02-05 11:01:35 119 3

原创 各种数据类型相加及强制转换

public class TTest { public static void main(String[] args) { byte b = 1;//取值范围-128到127 short s = 2;//取值范围-32768到32767 int i = 3; long l = 5l;//后缀必须加L,大小写都可 float f = 13.14f;//后缀必须加F,大小写都可 double d

2023-02-05 10:38:14 197 2

原创 Scanner键盘录入,打印个十百千位上的数字

import java.util.Scanner;public class TTest { public static void main (String [] args){ Scanner sc = new Scanner (System.in); System.out.println("请输入一个四位数1524"); int number1 = sc.nextInt();//int对应nextInt(),String对应nextStri

2023-02-05 10:32:25 88 4

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除