OLI 课程 & Java入学考试的五道题
Unit 1:: Programming with Java
✔️
机械、自动、不需要智慧地执行原始的内置指令。
字节码相同,JVM不同(体现平台)
✖️
In modern computers instructions can be stored and manipulated as other types of data. 对,都是位运算
We cannot describe an algorithm without a programming language.错,没有语言也可以写算法
compile:高级语言变成低级语言,设置一次就行,只翻译 不执行 很快,形成字节码。interpreter:要设置很多次,又翻译又执行。
z = x * y, 改y, z不变
用byte(带符号整数)存100。Although such data values can be stored in bigger numeric data types, e.g. short, int, or long, the most appropriate is byte as it takes least memory and has the range from -128 to 127.
double可以是也可以不是浮点型小数
打印前100个prime numbers
第一个x设为2,然后逐个往后试验
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in); int N = scan.nextInt();
int x = 2; for(int i = 0; i <= N; i++)
{
int count = 0; for(int j = 1; j <= x; j++)
if(x%j == 0)
count++; if(count == 2)
System.out.print(x + " "); x++;
}
}
class driverFuction {
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
int x = 2;
int n = scanner.nextInt();
//count for n numbers
for(int i = 0; i <= n; i++) {
//reset count = 0;
int count = 0;
for (int j = 1; j <= x; j++) {
if (x % j == 0) count++;
}
if (count == 2) System.out.println("prime is x = " + x);
//add x
x++;
}
}
}

import java.util.Scanner;
public class ExArraySortElement
{
public static void main(String[] args)
{
int n, temp;
//scanner class object creation
Scanner s = new Scanner(System.in); //input total number of elements to be read
System.out.print("Enter the elements you want : ");
n = s.nextInt(); //integer array object
int a[] = new int[n]; //read elements
System.out.println("Enter all the elements:");
for (int i = 0; i < n; i++)
{
a[i] = s.nextInt();
//数组中的元素需要一个个地输入
} //sorting elements
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n; j++)
{
if (a[i] > a[j])
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
} //print sorted elements
System.out.println("Ascending Order:");
for (int i = 0; i < n ; i++)
{
System.out.println(a[i]);
}
}
}
// package whatever; // don't place package name! import java.io.*;
import java.util.*;
import java.lang.*; class driverFuction {
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt(); //new an array
int[] nums = new int[n]; //input n numbers
for (int i = 0; i < n; i++) {
a[i] = scanner.nextInt();
} //sort
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (nums[i] > nums[j]) {
int temp = nums[i];
nums[i] = nums[j];
nums[j] = temp;
}
}
} //output
for (int i = 0; i < n; i++) {
System.out.println("nums[i] = " + nums[i]);
}
}
}
https://www.includehelp.com/java-programs/sort-an-array-in-ascending-order.aspx

import java.util.Scanner;
class PrimeCheck
{
public static void main(String args[])
{
int temp;
boolean isPrime=true;
Scanner scan= new Scanner(System.in);
System.out.println("Enter any number:");
//capture the input in an integer
int num=scan.nextInt();
scan.close();
for(int i=2;i<=num/2;i++)
{
temp=num%i;
if(temp==0)
{
isPrime=false;
break;
}
}
//If isPrime is true then the number is prime else not
if(isPrime)
System.out.println(num + " is a Prime Number");
else
System.out.println(num + " is not a Prime Number");
}
}
https://beginnersbook.com/2014/01/java-program-to-check-prime-number/

// package whatever; // don't place package name!
import java.io.*;
import java.util.*;
import java.lang.*;
class Palindrome
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
System.out.println("Enter a string to check if it is a palindrome");
String original = in.nextLine();
//int length = original.length();
String clean = original.replaceAll("\\s+", "").toLowerCase();
//单词里面有空格,要用replaceall
int length = clean.length();
int forward = 0;
int backward = length - 1;
while (backward > forward) {
char forwardChar = clean.charAt(forward++);
char backwardChar = clean.charAt(backward--);
if (forwardChar != backwardChar)
System.out.println("false");
}
System.out.println("true");
}
}

import java.io.*;
import java.util.*;
import java.lang.*;
class Palindrome
{
public static void main(String args[])
{
String word, File file;
int count = 0;
Scanner scanner = new Scanner(file);
while (scanner.hasNextLine()) {
String nextToken = scanner.next();//表示下一行
if (nextToken.equalsIgnoreCase(word))
count++;
}
return count;
}
}
OLI 课程 & Java入学考试的五道题的更多相关文章
- Java实现 蓝桥杯VIP 算法训练 入学考试
问题描述 辰辰是个天资聪颖的孩子,他的梦想是成为世界上最伟大的医师.为此,他想拜附近最有威望的医师为师.医师为了判断他的资质,给他出了一个难题.医师把他带到一个到处都是草药的山洞里对他说:" ...
- 算法历练之路——入学考试(JAVA)
入学考试 时间限制: 1Sec 内存限制: 128MB 提交: 42 解决: 18 题目描述辰辰是个天资聪颖的孩子,他的梦想是成为世界 上最伟大的医师.为此,他想拜附近最有威望的医师为师.医师为了判断 ...
- 20155312 2016-2017-2 《Java程序设计》第五周学习总结
20155312 2016-2017-2 <Java程序设计>第五周学习总结 课堂笔记 十个基本类型 命令:ascii打印ascii值, od -tx1 Test.java用十六进制查看代 ...
- 20155313 2016-2017-2 《Java程序设计》第五周学习总结
20155313 2016-2017-2 <Java程序设计>第五周学习总结 教材内容学习 第八章 异常处理 程序中总有些意想不到的状况所引发的错误,Java中的错误也以对象方式呈现为ja ...
- 20172306《Java程序设计》第五周学习总结
20172306 2016-2017-2 <Java程序设计>第五周学习总结 教材学习内容总结 第五章主要学习了if以及while的语句的运用 运算符:== 代表相等,是两个之间的内存地址 ...
- 20155303 2016-2017-2 《Java程序设计》第五周学习总结
20155303 2016-2017-2 <Java程序设计>第五周学习总结 教材学习中的问题和解决过程 『问题一』:受检异常与非受检异常 『问题一解决』: 受检异常:这种在编译时被强制检 ...
- 20155227 2016-2017-2 《Java程序设计》第五周学习总结
20155227 2016-2017-2 <Java程序设计>第五周学习总结 教材学习内容总结 语法与继承架构 使用try...catch JVM会尝试执行try区块中的程序代码,如果发生 ...
- 20155320 2016-2017-2 《Java程序设计》第五周学习总结
20155320 2016-2017-2 <Java程序设计>第五周学习总结 教材学习内容总结 错误处理 java中所有错误都会被打包为对象,可以通过try catch 代表错误的对象后做 ...
- 20145213《Java程序设计》第五周学习总结
20145213<Java程序设计>第五周学习总结 教材学习内容总结 "素衣莫起风尘叹,犹及清明可到家."每每念此,不得不心疼自己.古人清明长假都进城耍了,还担心自己清 ...
随机推荐
- Anatoly and Cockroaches
Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also li ...
- (考研)PV操作和信号量
就绪:除了CPU其他都行了 进程的阻塞:进程因等待某事件(如等待I/O设备,等待临街资源)而暂时不能运行的状态,此时即使处理机空闲,进程也无法使用. ************************* ...
- 网站配色、网站模板网址 UE样式 metro报表
http://www.colourlovers.com http://unmatchedstyle.com网站模板目录 花瓣 http://huaban.com/ 油表 http://fl ...
- maven下载源代码,中文注释乱码的处理方法
通过maven下载的源码,如果有注释是中文的话,一般会有乱码问题,解决办法如下: Window -> Preferences -> Content Types -> Text -&g ...
- ruby的代码风格
http://stylesror.github.io/ 大部分同意,有小部分,不敢苟同.
- 黄聪:win7 64位系统PS、AI、PSD缩略图预览补丁
MysticThumbs支持Windows 7 / Vista / XP,32位和64位.除了预览PSD以外,还支持DDS.SGI缩略图显示. Mystic Thumbs是一款用来支持win7 64位 ...
- bzoj1067 降雨量
Description 我们常常会说这样的话:“X年是自Y年以来降雨量最多的”.它的含义是X年的降雨量不超过Y年,且对于任意 Y<Z<X,Z年的降雨量严格小于X年.例如2002,2003, ...
- Python调用R语言
网络上经常看到有人问数据分析是学习Python好还是R语言好,还有一些争论Python好还是R好的文章.每次看到这样的文章我都会想到李舰和肖凯的<数据科学中的R语言>,书中一直强调,工具不 ...
- FilenameFilter 文件名过滤
public static final FilenameFilter JSON_CONFIG_FILE_FILTER = new FilenameFilter() { @Overrid ...
- 在ubuntu 18.04下,无线网卡无驱动,连不上wifi,显示wifi没有适配器的解决方法
近来因为做东西要用到linux环境,所以自己的笔记本在win10的系统上又安装了ubuntu 18.04版本的双系统,但是安装好以后,没有无线网卡的驱动,显示wifi没有适配器等字样,很纠结,前后研究 ...