0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

1週目Java 基礎

Posted at

第1週目
Java基礎文法
intを利用した変数指定入力
long、int、short、byteなどがあり、
float,double

boolean等の真の嘘のif文作成
文字は「」
文字列は";

小さいタイプのキャスティングに大きいのを入れる時
inti=(int)30L;こんな風にしなければならない

\n=改行を入れること
フォーマットを作って使うともっと楽だ

mathクラスmax(10,30)=30
min等

文字列数字相互変換
int i = Integer.parseInt(str);

String str2 = String.valurOf(i);
このように相互変換可能

ランダム値を受け取る
Random random = new Randon();
int rand = random.nextInt(bound4) + 5 //5
4までは走る

Javaで文字列を入力される場合
Scanner scan = new Scanner(System.in);

String str = scanner.next();
int i = scanner.nextInt();

if文
int i = 10;
if ( i<5 ){
System.out.println("力");
}else {
System.out.println("偽り");
}

このように最初のブロックを実行し、または2番目のブロックに移動
そうでなければelifで先に送ってelseで送る方法もある。

三項演算

boolean inMarried = true;
boolean isMan = false ;

String str;

str=isMarred?"結婚した"結婚してない";

if (isMarried) {
str=「結婚した」
}else{

str="結婚してない";

switch (str) {
case"結婚した":
System.out.println(“O”);
break;
case"結婚してない。 “ :
System.out.println(“X”);

defalut:
System.out.println(“?”);

}

System.out.println(“str”);

反復文
forムーン

for(int i = 0; i < 0 ; i++){

System.out.println(“i”);

while
int i = 0;
while (i<10){
System.out.println(“i”);
i++;
}

do while
int i = 0;
do {
System.out.println(i);
i++;
}while (i< 10);
}

break;止めて
continue;空振り

配列[]
{
int[] score = {10, 20, 30, 40 50};
int count = score.length;
System.out.println(score[score.length - 1]);
}

= 20

String[] names = new String[2];
ArrayList scoreList = new ArrayList<>();
scoreList.add(10);
scoreList.add(20);
scoreList.add(30);
scoreList.add(40);
scoreList.add(50);
System.out.println(scoreLsit);

マーサード

メインメソッド
System.out.println(add 50, 10, 30)

Public static int add(int x , int y, int z){
return x + y + z;
;

メインメソッド
System.out.println(add(1,2,3,4,5)); = 10
Public static int add(int … numbers){
int sum = 0;
for(int i = 0 ;i < numbers.length; i++)
sum = sum + 1;

return sum ;
;

こうやって作っておけば、呼び出して使用可能。
生成子

gettersetter作り

main
Person person = new Person();
personperson1=newPerson(name:"ホン·ギルドン,age:19);

class person{
private String name;
private int age ;

public Person(){

}

public person(String name , int age){
this.name = name ;
this.age = age ;

Public String getName(){
return name;

}
Public String setName(String name){
this.name = name

}
Public String getAge(){
return age;

}

Public String setAge(int age){
this.age = age

}

toStringに変換しなければならない。
@override

Javaは基本的に他のパッケージにあるものを使うにはインポートをしなければならない。

public他のパッケージでもアクセスできるか

相続 extendsPerson

public boolean isFlying(){
return isFlying;
} <飛ばし機能の追加

public void setFlying(){
isFlying = flying;
}

public void attack(Hero hero){

System.out.println(hero.getName()+"と喧嘩をした";

抽象
マーサードabstractvoid(Herohero);
@オーバーライドして相続した未完成クラスを使用するためにオーバーライドをしなければならない

抽象クラスはニューができない

インターフェース抽象クラスと同じ機能を持つ。

Javaは相続を単一支援だが相続のように指定も可能多重相続も可能

ジェネリック
ArrayList<>の中に入ってくるもの
どんなタイプでも中に入れるようにしてくれる

スレッド

ジャバは基本的にメインゴミとして使用される。
時間差で出力可能
For文などの応用が可能である

ラムダ式
抽象メソッドが一つしかない時に使うもの

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?