1.如何使用Scanne类来接收一个字符
我们可以调用scanner.next( ).charAt(0)的函数来接收
例题分享
习题分享
1.分享一个求平方根的方法
例题分享代码实现如下所示
import java.util.*;
class home28{
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
System.out.print(“Enter ten numbers :”);
int[] c= new int[0];
int temp=0;
for(int i=0;i<10;i++){
int num= scanner.nextInt();
if(!Contains(c,num)){
c=resize(c,c.length+1);
c[c.length-1]=num;
temp++;
}
}
System.out.println("The number of distinct number is "+temp);
System.out.println(“The distinct numbers are :”+Arrays.toString©);
}
public static boolean Contains(int []c,int num){
for(int i=0;i<c.length;i++){
if(c[i]==num){
return true;
}
}
return false;
}
public static int[] resize(int[] c,int newlen){
int[] news= new int[newlen];
for(int i=0;i<c.length;i++){
news[i]=c[i];
}
return news;
}
}
2.消除重复
a.第一种方法边进边消
例题分享b.数字全部读完之后再删
例题分享
3.求最小元素的下标
例题分享代码演示如下
例题分享

相关文章:

  • 2021-08-24
  • 2021-12-27
  • 2021-09-28
  • 2021-06-21
  • 2021-12-17
  • 2022-12-23
  • 2021-11-14
猜你喜欢
  • 2021-08-29
  • 2022-01-10
  • 2021-06-18
  • 2022-12-23
  • 2017-11-27
  • 2022-12-23
相关资源
相似解决方案