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程序设计>第五周学习总结 教材学习内容总结 "素衣莫起风尘叹,犹及清明可到家."每每念此,不得不心疼自己.古人清明长假都进城耍了,还担心自己清 ...
随机推荐
- 关于protel 99se 汉化后某些菜单消失的解决方法
本人在使用protel 99se 画PCB时,遇到了好些问题,通过网上查资料基本都解决了. 下面给大家分享 关于protel 99se 汉化后某些菜单消失的解决方法. 其他的许多看不见的菜单也可以自己 ...
- Oracle(一)安装
一.到官网或者哪里去下载Oracle,我下的是winX64的11g版本 官网:https://www.oracle.com/technetwork/database/enterprise-editio ...
- IOS中UITableViewCell使用详解
IOS中UITableViewCell使用详解 - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(N ...
- jenkins执行shell命令,有时会提示“Command not found”
这个问题其实就是环境变量没有配准确 (1)检查你在Jenkins中设置的maven是否准确,可以通过[new job]按钮查看新建job中是否有maven选项,没有就是你配置的不准确 如果你下载的插件 ...
- java利用freemarker导出world
一.简单导出(不含循环导出) 1.新建一个word文件.如下图: 2.使用word将文件另存为xml的格式 3.编辑xml文件内容,将'用户名'替换成-> ${username}.'简介'替换成 ...
- 《FDTD electromagnetic field using MATLAB》读书笔记之一阶、二阶偏导数差商近似
- 使用Spec Markdown 编写手册文档
Spec Markdown 是一个基于markdown 的文档编写工具,安装简单,可以让我们编写出专业的文档 参考项目 https://github.com/rongfengliang/spec-md ...
- Spring4源码解析:BeanDefinition架构及实现
一.架构图 首先共同看下总体的 Java Class Diagrams 图: 二.具体类实现 2.1 AttributeAccessor 接口定义了一个通用的可对任意对象获取.修改等操作元数据的附加契 ...
- php 取数组最后一个元素
可以用end()函数取出数组的最后一个元素, $rList = array( array('id'=>1,'txt'=>'a'), array('id'=>2,'txt'=>' ...
- mkdir -p 多层次目录创建
mkdir的-p选项允许你一次性创建多层次的目录,而不是一次只创建单独的目录.例如,我们要在当前目录创建目录Projects/a/src,使用命令 1 mkdir -p Project/a/src 而 ...