複数整数の最小値 Java
paizaラーニングDランク相当の問題ググりつつ解きました。
参考にしたサイトです。ありがとうございました!
こちらも参考にしたサイトです。ありがとうございました!www.cc.kyoto-su.ac.jp
(codeコピペすると当たり前だけどインデントされないからしんどい)
本題を書いて行きます。
〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜
import java.util.*; //呪文
public class Main {
public static void main(String args) {
// 自分の得意な言語で
// Let's チャレンジ!!
Scanner sc = new Scanner(System.in); //泥臭く一行ずつ入力されている値を取得
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
int d = sc.nextInt();
int e = sc.nextInt();
int array = {a,b,c,d,e}; // ↑で取得した値で配列の宣言と、初期化
int min = a; // 暫定で変数minを用意し、a~eのいずれかで初期化(どれでもよかった)
for (int i = 0; i < array.length ; i++ ){
if(min > array[i]){
min = array[i];
}
}
System.out.println(min);
}
}
〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜
paiza 問題
n回出力し、最後スペースを入れない。。。
わからんすぎてググリ、辿り着いた結果↓
【paizaラーニング Cランクレベルアップメニュー 半角スペース区切りでの出力 (paizaランク D 相当)※自分のための備忘録】|友季子|note
import java.util.*;
public class Main {
public static void main(String[] args) {
// 自分の得意な言語で
// Let's チャレンジ!!
Scanner sc = new Scanner(System.in);
int line = sc.nextInt();
for (int x =0 ; x < line ; x++) {
System.out.print("paiza");
if (x < line-1){
System.out.print(" ");
}
}
}
}
一行目の値を取得して繰り返す
メモ
import java.util.*;
public class Main {
public static void main(String args) {
Scanner sc = new Scanner(System.in);
int count = sc.nextInt(); //一行目を読み込む
//System.out.println(count);
int date; //dateがint型であると宣言
for (int x = 0; x < count ; x++ ){
date = sc.nextInt(); //二行目から↑のcount変数分データ出力
System.out.println(date);
}
}
}
若しくは
import java.util.*;
public class Main {
public static void main(String args) {
Scanner sc = new Scanner(System.in);
int count = sc.nextInt(); //一行目を読み込む
//System.out.println(count);
for (int x = 0; x < count ; x++ ){
int date = sc.nextInt(); //dateをint変数宣言しつつ、二行目から↑のcount変数分データ出力
System.out.println(date);
}
}
}
*********************
「入力」
3
4
5
6
*********************
「出力」
4
5
6
ということか