日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > java >内容正文

java

OLI 课程 Java入学考试的五道题

發(fā)布時(shí)間:2024/4/15 java 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 OLI 课程 Java入学考试的五道题 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

Unit? 1::?Programming with Java

???

機(jī)械、自動(dòng)、不需要智慧地執(zhí)行原始的內(nèi)置指令。

字節(jié)碼相同,JVM不同(體現(xiàn)平臺

?

?

??

In modern computers instructions can be stored and manipulated as other types of data. 對,都是位運(yùn)算

We cannot describe an algorithm without a programming language.錯(cuò),沒有語言也可以寫算法

compile:高級語言變成低級語言,設(shè)置一次就行,只翻譯 不執(zhí)行 很快,形成字節(jié)碼。interpreter:要設(shè)置很多次,又翻譯又執(zhí)行。

?z = x * y, 改y, z不變

byte(帶符號整數(shù))存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可以是也可以不是浮點(diǎn)型小數(shù)?

?

打印前100個(gè)prime numbers

第一個(gè)x設(shè)為2,然后逐個(gè)往后試驗(yàn)

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 creationScanner s = new Scanner(System.in);//input total number of elements to be readSystem.out.print("Enter the elements you want : ");n = s.nextInt();//integer array objectint a[] = new int[n];//read elements System.out.println("Enter all the elements:");for (int i = 0; i < n; i++) {a[i] = s.nextInt();
//數(shù)組中的元素需要一個(gè)個(gè)地輸入
}
//sorting elementsfor (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 arrayint[] nums = new int[n];//input n numbersfor (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;}}}//outputfor (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 integerint 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 notif(isPrime)System.out.println(num + " is a Prime Number");elseSystem.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;
}
}

?



?

轉(zhuǎn)載于:https://www.cnblogs.com/immiao0319/p/9164701.html

總結(jié)

以上是生活随笔為你收集整理的OLI 课程 Java入学考试的五道题的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。